The relationship between JDK, JRE and JVM in Java

http://www.cnblogs.com/xiaofeixiang/p/4085159.html

Beginner JAVA is easy to be confused by many of the concepts. First of all, let’s understand it conceptually. JDK (Java Development Kit) is simple to understand. It is the Java Development Kit, JRE (Java Runtime Environment) is the running environment of Java, and JVM (java virtual machine) is often heard of the Java virtual machine. JDK is for developers, and JRE is for users who use JAVA programs. The above is just a simple difference. Generally, there are many concepts on the Internet. I will not talk about it. Direct screenshots should be clearer. I installed JDK1.8, The effect is shown in the figure:



JDK and JRE

found through the above figure that there are two JRE folders. If you look closely, the content inside is basically the same. If you are just a Java program user, then there will only be the outermost JRE directory. , JDK comes with JRE. If you install JDK, there will be a JRE in it. So the question is, why are there two sets of JRE?

When you first use JAVA, when setting the JAVA environment variable, in addition to setting the JDK path in JAVA_Home, you also need to set ClassPath,%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;dt. Jar and tools.jar are the two most basic packages of java, which contain the most important lang packages from java to various advanced functions such as visual swing packages, which are essential for java. The bin under the path contains the executable compiler of java and its tools, such as java, javadoc, etc. You run cmd under any folder and type javac, and the system can automatically summon the java compiler. This is due to this Setting of environment variables; if you modify the name of tools.jar, an error will be reported when cmd runs:



The reason for the error is that the entered javac command is not javac.exe found in the bin directory in the JDK, but is executed in com.sun.tools.javac.Main in the tools.jar in the lib directory of the JDK, so javac. exe is just a wrapper (Wrapper), the purpose of existence is to save developers from entering too long commands. At this time, it is found that the tools in the JDK are almost written in Java, which belong to Java applications. Therefore, the tools attached to the JDK are used to develop Java programs, so a set of JRE is required to run them. The JRE in the same directory as jdk in the above figure is used to run general Java programs. When the two sets of JREs are running, which one is running

? At this time, java.exe in the JDK is first searched from its own directory, and then found in the parent directory.



It has a lot to do with which JRE is executed in your computer. JDK and JRE should be finished. Let's talk about JRE and JVM.

JRE and JVM

JVM -- java virtual machineJVM 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 executed on the virtual machine. The class file does not directly correspond to the machine's operating system, but It interacts with the operating system indirectly through the virtual machine, and the virtual machine interprets the program to the local system for execution, similar to the CLR in C#.

The JVM cannot handle the execution of the class alone. When interpreting the class, the JVM needs to call the class library lib required for the interpretation. There are two folders bin and lib in the jre directory under the JDK. Here, it can be considered that the jvm in the bin, the class library required for the jvm work in the lib, and the jvm and the lib together are called jre. JVM+Lib=JRE, if the specific point is the jvm.dll file in the bin directory, jvm.dll cannot work alone, when jvm.dll is started, it will use the explicit method (that is, use LoadLibrary( in the Win32 API). ) and GetProcAddress() to load auxiliary dynamic link libraries), and these auxiliary dynamic link libraries (.dll) must be located in the parent directory of the directory where jvm.dll is located. So if you want to use which JVM, you only need to set the PATH to point to jvm.dll in the directory where the JRE is located.





JDK is still a vague concept so far. At this time, you can look at it through the JDK directory file:



there are five folders, a src class library source code package and several declaration files under the directory, and the other five folders are : bin, db, include, lib, jre, db depends on the business requirements ~

bin: the most important thing is the compiler (javac.exe);

db: jdk has built-in Derby database since 1.6, it is a pure Java The implemented in-memory database belongs to an open source project of Apache. It is implemented in Java, so it can run on any platform; another feature is that it is small in size, free of installation, and only needs a few small jar packages to run.

include: header files for interaction between java and JVM;

lib: common class library

jre: java runtime environment

JDK includes JRE, and JRE includes JVM. In general, JDK is used for the development of java programs, while jre can only run classes without compiling. Other IDEs such as Eclipse and IntelliJ IDEA have their own compilers instead of Use the one that comes with the JDK bin directory, so you only need to select the jre path during installation, and finally summarize it with a network picture:


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326249462&siteId=291194637