In Java, the native method refers to a local method that is declared as the native method when it calls code in a method that is not written by the Java language or when the computer hardware is manipulated directly in the Java language in a method. The execution of the Native method relies on the designer of the JVM, such as in the Sun HotSpot (JVM), for localization through the API interface of the JNI (Java Native Interface). The native method is commonly used in two situations: 1) Calling code in a method that is not written by the Java language. 2) manipulate the computer hardware directly in the Java language in the method. When defining a native method, the implementation body is not provided (some like defining a Java interface) because its implementation is implemented outside of the Java language, and an example is given below:?
| 12345 |
publicclassINativeDemo{ nativepublicvoidNative1(intx); nativestaticpubliclongNative2(); nativesynchronizedprivatefloatNative3(Object o);} |
The native identifier can be used with all other Java identifiers, except for abstract. Because the native identifier implies that these methods are implemented, only those implementations are non-Java, but abstract clearly indicates that these methods are not implemented. Native and other Java identity connect prompt when used, and the same Java common method is not different, such as native static indicates that this method can not produce an instance of the class directly called. The third method above uses the native SYNCHRONIZED,JVM to perform a synchronous lock mechanism before entering the implementation of this method. The presence of the native method does not have any effect on other classes calling these local methods, and the other classes that actually call these methods do not even know that it is calling a local method. If a class containing a local method is inherited, the subclass inherits the local method and can override the method in the Java language, as well as if a local method is fianl identified, it cannot be overridden after it is inherited.
Native as Local method