JDK contains JRE

JDK is the Java Development Kit. Simply put, JDK is an SDK for developers. It provides a Java development environment and operating environment. SDK is Software Development Kit generally refers to software development kit, which can include function library, compiler, etc.
JRE is Java Runtime Enviroment refers to the operating environment of Java, which is for users of Java programs, not developers.
If the JDK is installed, your computer will have two sets of JRE, one is located in \jre and the other is located in the C:\Program Files\Java\jre1.5.0_15 directory, the latter one is less Server than the previous one The Java virtual machine on the server side, but just copy the previous server side Java virtual machine. And you can choose whether to install this JRE located in the C:\Program Files\Java directory when installing the JDK. If you only install JRE instead of JDK, only one set of JRE 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 be run by JRE. So after you install the JDK, if you install two sets of JRE in two different places on the hard disk, then you can imagine that your computer has two virtual Java PCs, both of which have the function of running 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 ask JDK to install two sets of the same JRE?
This is because there are many development tools written in Java (such as javac.exe, jar.exe, etc.) in the JDK, and they are all placed in \lib\tools.jar. As can be seen from the following example, first rename tools.jar to tools1.jar, and then run javac.exe, the following result is displayed: Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/javac /Main this It means that you enter javac.exe and enter java -cp c:\jdk\lib\tools.jar com.sun.tools.javac.Main are the same, and you will get the same result. From here we can prove that javac.exe is just a wrapper, and the purpose of making it is to prevent developers from typing too long instructions. And it can be found that the programs in the \lib directory are very small, no more than 29K, from which we can draw a conclusion. That is, the tools in the JDK are almost written in Java, so they are also Java applications. Therefore, to use the tools attached to the JDK to develop Java programs, you must also attach a set of JRE yourself, so it is located in C:\Program Files\ The JRE in the Java directory is used to run general Java programs.
2. If two or more JREs are installed on a computer, who decides?
This major task falls on java.exe. The job of Java.exe is to find a suitable JRE to run Java programs. Java.exe searches for JRE in the following order: Is there JRE in its own directory; Is there JRE in the parent directory; Query the registry: [HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment] So the running result of java.exe is consistent with your Which JRE is executed in the computer has a lot to do.

ADD: (Summary)
1. JVM - java virtual machine JVM is what we often call the java virtual machine. It is the core part of the entire java implementation of cross-platform. All java programs will first be compiled into .class class files, which can be found in Execution on the virtual machine means that the class does not directly correspond to the machine's operating system, but indirectly interacts with the operating system through the virtual machine, and the virtual machine interprets the program to the local system for execution. 2. JRE - java runtime environment JRE refers to the java runtime environment. The JVM alone cannot be the execution of the class, because the JVM needs to call the class library lib required for the interpretation when interpreting the class. You can find the jre directory in the JDK installation directory. There are two folders bin and lib. Here you can think that the bin is jvm, and the lib is the class library needed for jvm work, and jvm and lib are combined It's called jre. So, after you write the java program and compile it into a .class, you can package the .class file with jre and send it to your friends, so that your friends can run your program. (There is java.exe running .class in jre) 3.JDK - java development kitJDK is a java development kit. Basically everyone who learns java will install a JDK on the machine first, so what parts does it contain? ? Let's take a look at the JDK installation directory. There are six folders, a src class library source code compression package, and several other declaration files under the directory. Among them, the following four folders really work when running java: bin, include, lib, jre. Now we can see such a relationship, JDK contains JRE, and JRE contains JVM. bin: The most important thing is the compiler (javac.exe) include: header files used for interaction between java and JVM lib: class library jre: java operating environment (note: the bin and lib folders here and the bin and lib in jre are Different) Generally speaking, JDK is used for the development of java programs, while jre can only run classes without compiling functions.
eclipse、idea等其他IDE有自己的编译器而不是用JDK bin目录中自带的,所以在安装时你会发现他们只要求你选中jre路径就ok了。

Guess you like

Origin blog.csdn.net/u010682774/article/details/20665679