Native as Local method

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.