Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the relationship between JDK and JRE and JVM

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article is to share with you about the relationship between JDK and JRE as well as JVM. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

If JDK is installed, there will be two sets of JRE on your computer, one located in\\ jre and the other in the C:\\ Program Files\\ Java\\ j2re1.4.1_01 directory with fewer Java virtual machines than the previous one, but just copy the Server Java virtual machine from the previous set. And when installing JDK, you can choose whether or not to install the JRE located in the C:\\ Program Files\\ Java directory. If you only install JRE, not JDK, only a set of JRE of * * will be installed in the C:\\ Program Files\\ Java directory. The status of JRE is like a PC, the Win32 applications we write need the operating system to help us run, similarly, the Java programs we write must also need JRE to run. So after you install JDK, if you install two sets of JRE in two different places on your hard drive, you can imagine that your computer has two virtual Java PCs, both of which can run Java programs. So we can say that as long as your computer has JRE installed, you can run Java applications correctly.

1. Why does Sun want JDK to install two identical sets of JRE? This is because there are many development tools (such as javac.exe, jar.exe, etc.) written in Java in JDK, and they are all placed in\\ lib\\ tools.jar. As you can see from the following example, first rename tools.jar to to ols1.jar, and then run javac.exe to display the following result: Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/javac / Main this means that you enter javac.exe and enter java-cp c:\ jdk\ lib\ tools.jar com.sun.tools.javac.Main is the same, you will get the same result. From here we can prove that javac.exe is just a Wrapper, and it is designed to save developers from typing too long instructions. And we can find that the programs in the\\ lib directory are very small, no more than 29K, from which we can draw a conclusion. Even the tools in JDK are almost written in Java, so they are also Java applications, so if you want to use the tools attached to JDK to develop Java programs, you must have your own set of JRE, so the set of JRE located in the C:\\ Program Files\\ Java directory is used to run general Java programs.

2. If more than two sets of JRE are installed on a computer, who will decide? This important task falls to java.exe. Java.exe 's job is to find the right JRE to run the Java program. Java.exe looks for JRE in the following order: is there a JRE; parent directory in your directory? JRE; queries the registry: [HKEY_LOCAL_MACHINE\\ SOFTWARE\\ JavaSoft\\ Java Runtime Environment] so the running result of java.exe has a lot to do with which JRE is executed on your computer.

3. Introduce the Bin directory under the JVM JRE directory. There are two directories: server and client. This is where the real jvm.dll is. Jvm.dll cannot work alone, and when jvm.dll starts, it uses the explicit method (that is, using LoadLibrary () and GetProcAddress () in Win32 API to load auxiliary dynamic link libraries), and these auxiliary dynamic link libraries (. Dll) must be located in the parent directory of the directory where the jvm.dll is located. So which JVM you want to use, just set PATH and point to jvm.dll under the directory where JRE is located.

The above is the relationship between JDK and JRE as well as JVM. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report