One Java question every day [9], a java question
Question
What is the role of the native keyword?
Answer
First, you need to understand JNI (Java Native Interface), which is an API connecting Java platform with local C code.
Second, the method declared with the native keyword is to tell JVM that the method called is an external defined method, that is, a method defined by local C code.
To sum up, the specific function of the native keyword is to use the method it declares without Java code implementation. Instead, the JVM uses JNI to load the local system C/C ++ DLL, and then calls the method to implement it.
Divergent thinking
1. Which method we usually use is declared with the native keyword?
Answer: hashCode method in java. lang. Object source code:
Public native int hashCode ();
2. When do we usually use the native keyword?
Answer:
And so on.
References
1. The role of the general Native keyword in Java (http://www.cnblogs.com/Qian123/p/5702574.html)