Why FFM over JNI
Safer native interop.
Calling Native Code
Java sometimes needs to call C libraries or work with off-heap memory. The classic way was the Java Native Interface (JNI). The modern way is the Foreign Function and Memory API (FFM), finalized in Java 22 (JEP 454).
This lesson explains why FFM is the better choice.
What JNI Required
JNI was painful:
- Write C glue code with awkward
JNIEXPORTsignatures - Compile a native shared library per platform
- Manually convert between Java and C types
- Easy to crash the JVM with a mistake
All lessons in this course
- Why FFM over JNI
- MemorySegment and Arena
- Downcall Handles
- Layouts and Structs