The native modifier, which is used for creating native methods
Previous | Home | Next |
The native modifier, which is used for creating native methods indicates that a method is implemented in platform-dependent code.Native can applied to methods only ,not classes ,not variables.
In the case of native, the implementation of the method exists in a library outside the JVM.
The native modifier indicates that this method is implemented in another language.
Also, the native method declaration is terminated with a semicolon, the statement terminator symbol,
because there is no implementation for native methods in the class itself.
Syntax of Native modifier
private native void print();
In this program private native void print () is a native method ,and new world() is the main method which calls the
native method but the last part of the class is the static initializer that loads the native library that contains the implementation of print native method.
class World {
private native void print();
public static void main(String[] args) {
new World().print();
}
static {
System.loadLibrary("HelloWorld !");
}
}
Previous | Home | Next |