Relationship between JDK, JRE, and JVM

Source: Internet
Author: User
Http://blog.csdn.net/sunboy_2050/article/details/6252552

 

If JDK is installed, there will be two sets of JRE with your computer,
A set <JDK installation directory>/JRE
AnotherC:/program files/Java/j2re1.4.1 _ 01 Directory
This later set is less server-side Java virtual machine than the previous one, but simply copy the previous server-side Java virtual machine. When installing JDK, you can choose whether to install the JRE in the C:/program files/Java directory.
If you only install JRE instead of JDK, only a unique set of JRE will be installed in the C:/program files/Java directory.

The status of JRE is just like that of a PC. We have written Win32 applications. Program The operating system is required to help us run the program. Similarly, the Java program we compile must also run JRE. So after installing JDK, if two sets of JRE are installed in two different locations on the hard disk, you can imagine that your computer has two virtual Java PCs, all have the function of running Java programs. So we can say that if your computer has installed JRE, you can run the Java application correctly.

1. Why does Sun need JDK to install two identical JRE?
This is because JDK has a lot of Java-compiled development tools (such as javac.exe‑jar.exe) and <JDK installation directory>/lib/tools. Jar . As shown in the following example, change tools.jarto tools1.jar, and then run javac.exe. the following result is displayed:
Exception in thread "Main" Java. Lang. noclassdeffounderror: COM/Sun/tools/javac/main
In this case, you enter javac.exe and

 

Java-cp c:/JDK/lib/tools. Jar com. Sun. Tools. javac. Main


The results are the same.
From this we can prove that javac.exe is just a wrapper, and the purpose is to prevent developers from entering too long fingers. We can also find that the program in the <JDK installation directory>/lib directory is very small, not greater than 29 K. Here we can draw a conclusion. That is, JDK tools are almost written in Java, so they are also Java applications. Therefore, to use the tools attached to JDK to develop Java programs, you must also attach a set of JRE, therefore C:/program files/the JRE under the Java directory is used to run general Java programs .

2. If two or more JRE are installed on a computer, who will decide?
This major task falls on java.exe. The job of java.exe is to find the appropriate JRE to run the Java program.
Java.exe searches for jre in the following order:
Is there any JRE under your own directory;
Does the parent directory contain JRE;
Query the registry:
[HKEY_LOCAL_MACHINE/software/javasoft/Java Runtime Environment]
The running result of java.exe has a great relationship with which JRE is executed on your computer.

3. Introduction to JVM
The bin directory under the JRE directory has two directories: server and client. This is where the real JVM. dll is located.
JVM. DLL cannot work independently when JVM. after the DLL is started, it will use the explicit method (that is, using loadlibrary () and getprocaddress () in the Win32 API to load the dynamic link library of the auxiliary ), these auxiliary Dynamic Link Libraries (. DLL) must be in the JVM. the parent directory of the dll Directory.
Therefore, you only need to set the path to the JVM. dll under the directory where JRE is located.

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.