In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article focuses on "what are the advantages of the local method interface". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn what are the advantages of the local method interface.
Local method interface what is a local method
In a nutshell, a Native Method is an interface for Java to call non-Java code. A Native Method is a Java method that is implemented in a non-Java language, such as C. This feature is not unique to Java. Many other programming languages have this mechanism. In C++, for example, you can use extern "c" to tell C++ compiler to call a c function.
"A native method is a Java method whose implementation is provided by non-java code." (the local method is a Java method, and its concrete implementation is the implementation of non-Java code)
When defining a native method, the implementation body is not provided (somewhat like defining a Java interface), because the actual body is actually implemented outside by a non-java language.
The function of the local interface is to integrate different programming languages for the use of Java, and its original intention is to integrate the CumberCraft + program.
The code illustrates how the Native method is written
/ * Local method * * / public class IhaveNatives {public native void Native1 (int x); native static public long Native2 (); native synchronized private float Native3 (Object o); native void Natives (int [] ary) throws Exception;}
It is important to note that the identifier native can be used with other java identifiers, except for abstract
Why use Native Method?
Java is very convenient to use, but some levels of tasks are not easy to implement with Java, or when we are very concerned about the efficiency of the program, the problem arises.
Interaction with the Java environment
Sometimes Java applications need to interact with the environment outside the Java, which is the main reason for the existence of local methods. You can think about what happens when Java needs to exchange information with some underlying system, such as the operating system or some hardware. The local approach is such a communication mechanism: it provides us with a very concise interface, and we don't need to know the tedious details outside of Java applications.
Interaction with the operating system
JVM supports the Java language itself and the runtime library. It is the platform on which Java programs live. It consists of an interpreter (interpreting bytecode) and libraries connected to native code. However, it is not a complete system after all, and it often depends on the support of an underlying system. These underlying systems are often powerful operating systems. By using local methods, we are able to use Java to interact with the underlying system of jre, and even some parts of JVM are written in c. Also, if we are going to use some features of the operating system that are not encapsulated in the Java language itself, we also need to use local methods.
Sun's Java
Sun's interpreter is implemented in C, which allows it to interact with the outside world like some ordinary C. Jre is mostly implemented in Java, and it also interacts with the outside world through some native methods. For example, the setpriority () method of the class java.lang.Thread is implemented in Java, but its implementation calls the local method setpriorityo () in the class. This native method is implemented in C and is embedded inside JVM, and on Windows 95 platforms, this native method will eventually call Win32 setpriority () ApI. This is a concrete implementation of a local method provided directly by JVM, and more often provided by an external dynamic link library (external dynamic link library) and then called by JVw.
Current situation
At present, this method is used less and less, unless it is hardware-related applications, such as Java programs to drive printers or Java systems to manage production devices, which are relatively rare in enterprise applications. Because now the communication between heterogeneous fields is very developed, for example, you can use Socket communication, you can also use Web Service and so on, without much introduction.
At this point, I believe you have a deeper understanding of "what are the advantages of the local method interface". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.