Java / JVM Architecture (Java21) Interview questions
What is the purpose of the Java Native Interface (JNI)?
The Java Native Interface (JNI) lets Java code call functions written in native languages like C or C++, and lets native code call back into Java objects and methods.
It is used when an application needs to reach platform-specific APIs the JDK does not expose, reuse an existing native library, or hand off performance-critical work to hand-tuned native code.
The trade-off is that JNI calls cross a real boundary: they bypass some JVM safety guarantees, add per-call overhead, and a native crash can bring down the whole JVM process instead of throwing a catchable exception.
Java 21 also ships the Foreign Function & Memory API (JEP 442, a preview feature) as a safer, easier-to-use alternative for calling native code without writing JNI glue code.
More Related questions...