Java Native Interface allows Java code running on the JVM to call native applications and libraries written in languages such as C or C++.
public class NativeHello {
static {
System.loadLibrary("nativehello");
}
private native void sayHello();
public static void main(String[] args) {
new NativeHello().sayHello();
}
}
JNI is useful when you need to integrate with platform-specific APIs or reuse existing native libraries.