How to find the c/c ++ source code corresponding to java, java source code
Many times, java is often despised by c, because c says that I am your foundation, but java has such a strong vitality that it must have its own value. This article does not discuss the advantages and disadvantages of various development languages. It only describes how to find the source code of c/c ++ implementation corresponding to java. When we hold a java class to the jdk library, we may encounter a method declared as native. Yes, it indicates that it is a local method implemented by c/c ++, at runtime, JVM will find the corresponding c/c ++ function through certain ing rules.
If you have used jni, you will be familiar with this ing. For example, if you have a java class InvokeCpp, it calls the hello function of the Test. dll dynamic link library. C that implements the dynamic link library must contain header files and C files. java also provides the javah tool to facilitate developers to generate header files. The detailed implementation is not described here. It is not covered in this article. At last, java calls the Java_com_seaboat_cpp_InvokeCpp_hello function in C language, it can be seen that it is a function name assembled by three underscores: Java, package name, and method.
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 discussing jni, return to the subject. To view the native method in jdk, first put the openjdk source code down. Its directory structure is as follows. jdk/src basically contains most of the native methods of jdk, among them, share is shared by multiple systems, while other linux, solaris, and windows are exclusive to their respective operating systems.
Suppose we are looking for java. lang. the local public native String intern () method in the String class can be found in the share/native/java/lang directory. c, Java_java_lang_String_intern is the corresponding C function source code.