Many times Java is often despised by C, because C says I am your foundation, but Java unexpectedly has such strong vitality will inevitably have its existence value. This article does not discuss the pros and cons of a variety of development languages, just how to find the Java corresponding code for C + + implementation. When we pursue a Java class to the JDK library, we may encounter a method that is declared as native, yes, it indicates a native method implemented by C/s + +, at run time the JVM will find the corresponding C + + function through a certain mapping rule.
If you have used JNI to be familiar with this mapping, such as a Java class invokecpp, it calls the Hello function of the Test.dll dynamic link library. To implement the dynamic link library c to include header files and C files, Java also provides the Javah tool to facilitate developers to generate header files. Detailed how to implement here no longer repeat, not in the scope of this article, the last Java call is the C language Java_com_seaboat_cpp_invokecpp_hello function, you can see is by Java, package name, method three with the underscore a function name assembled together.
Package com.seaboat.cpp;
public class invokecpp{
static{
System.loadlibrary ("Test");
}
public native void Hello (String str);
public static void Main (string[] args) {
New Invokecpp (). Hello ("Hello");
}
}
After the discussion of JNI back to the point, to see the JDK native method first to the OPENJDK source down, its directory structure as follows, Jdk/src basically contains most of the JDK native method, where share is shared by multiple systems, other Linux, Solaris, Windows are unique to their respective operating systems.
If we're looking for public native String intern () in the Java.lang.String class, the local method can be found in the Share/native/java/lang directory String.c,java_java_lang_ String_intern is the corresponding C function source code.
How to find Java-C + + source code