0Pricing
Java Academy · Lesson

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 JNIEXPORT signatures
  • 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

  1. Why FFM over JNI
  2. MemorySegment and Arena
  3. Downcall Handles
  4. Layouts and Structs
← Back to Java Academy