How to find Java-C + + source code

Source: Internet
Author: User

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

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.