Java native Keyword
Example
Load a method from a compiled library:
class Main {
static {
System.loadLibrary("libraryname");
}
public static void main(String[] args) {
test();
}
private static native void test();
}
Definition and Usage
The native
keyword declares a method as belonging to an external compiled library which is native to the operating system.
In order to use native methods, an external library must be loaded from a .dll
, .so
or similar kind of file. The compiled code in the external file should be written to support the Java Native Interface.