Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to execute HelloWorld with OpenJDK source code

Shulou Source: shulou.com Published: 2022-06-02 01:33:52 09月14日 Update

This article will explain in detail how to use OpenJDK source code to implement HelloWorld, the quality of the article is high, so Xiaobian shares it with you as a reference, I hope you have a certain understanding of related knowledge after reading this article.

HelloWorld in Java

Usually when we run java programs, there are generally two options, 1 is to run the program directly on the server with java -jar command, 2 is to click Run/debug directly in idea, as shown in the following figure:

What if one day we get out of idea and we run this on the command line?

In fact, idea has already helped us generate, as shown in the first line of the figure below

We take the following from above, copy it to the command line, and we run it.

/Users/lixiang/soft/jdk-11.0.2.jdk/Contents/Home/bin/java -Dfile.encoding=UTF-8 -classpath /Users/lixiang/code/tools/tools-java/out/production/classes com.platform.tools.jvm.Main

This is shown in Figure 1.

Run java code in CLON

Run java code in Clion, mainly the java command in front, compiled by ourselves, and then directly copy the parameters behind it, as shown in the following figure:

Then click Run and you will see our java code output as shown below in the ClionDebug panel

JVM executes Java code

Here we're going to continue with yesterday's version number output. In java.c file line 508, you can see the class where the main function is loaded.

After clicking on it, you can see it. In fact, it is still the java class requested, as shown in the following figure:

1. Go and find this class dot. After entering, you can see that it is this class sun/launcher/LauncherHelper.

2. Find the checkAndLoadMain method in the class above

3. This method has Z(Boolean),I(integer type),String type input parameters

The return value of this method is Class.

Based on this condition, we can find the following method in Idea

Then we trace it all the way down, you can see, finally to the ClassLoader.java defineClass1 this native method,native method and jdk source code corresponding to us later together to learn.

After the LoadMainClass() method, we can see CreateApplicationArgs creating the application's parameter method, looking for the Main method, executing the Main method, as follows:

About how to use OpenJDK source code to implement HelloWorld to share here, I hope the above content can be of some help to everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.

Tags: Method run command code source code content type parameter article is in more knowledge program article output good one line use in function actual Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Redmi vpn Xiaomi MySQL