How to find the c/c ++ source code corresponding to java, java source code

Source: Internet
Author: User

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.


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.