For twenty years, off-heap buffers and C interoperability meant slow JNI boilerplate or unsafe sun.misc.Unsafe raw pointers that risked JVM segfaults and leaked native RAM forever. Finalized in Java 22 (JEP 454), java.lang.foreign replaces both safely with deterministic Arena lifetimes and bounds-checked MemorySegments.
More lessons in Complete Core Java