Differences and connections between JVM JRE JDK

1. Detailed introduction
1. JVM -- java virtual machine
JVM is what we often call the java virtual machine. It is the core part of the cross-platform implementation of the entire java. All java programs will first be compiled into .class class files. This class file can be executed on a virtual machine, that is to say, the class does not directly correspond to the operating system of the machine, but indirectly interacts with the operating system through the virtual machine, and the virtual machine interprets the program to the local system for execution.
The JVM is the foundation of the Java platform, and like an actual machine, it has its own instruction set and operates on different memory regions at runtime. JVM provides a platform-independent code execution method by abstracting the operating system and CPU structure, that is, independent of special implementation methods, host hardware, and host operating systems. But in some small aspects, the implementation of JVM is also different from each other, such as garbage collection  algorithm, thread scheduling algorithm (may have different implementations for different OS). 
The main job of the JVM is to interpret its own instruction set (ie, bytecode) to the CPU's instruction set or the OS's system calls to protect users from being harassed by malicious programs. The JVM does not care about the upper Java source files, it only cares about the class files (class files) generated by the source files. The composition of the class file includes the JVM instruction set, the symbol table and some supplementary information.
2. JRE -- java runtime environment
JRE refers to the java runtime environment. The JVM alone cannot execute the class, because when interpreting the class, the JVM needs to call the class library lib required for the interpretation. In the JDK installation directory, you can find the jre directory, which has two folders bin and lib. Here, you can think that the bin is the jvm, and the lib is the class library required for the jvm to work, and the jvm and lib are combined. It's called jre. So, after you write the java program and compile it into .class, you can package the .class file  with jre and send it to your friends, so that your friends can run the program you wrote. (Jre has java.exe running .class)
JRE is a larger system released by Sun, which has a JVM in it. The JRE is related to the specific CPU structure and operating system. When we downloaded the JRE from Sun, we saw different versions. There are some APIs (such as awt, swing, etc.) that make up the JRE with the JVM. The JRE is essential for running Java programs.
JRE (Java Runtime Environment) is essential for running Java programs (unless compiled into .exe executable files with some other compilation environment...), the status of JRE is like a PC, and the Win32 application we wrote The program needs the operating system to help us run, and similarly, the Java program we write must also need the JRE to run.
There is a JVM in the JRE. The JRE is related to the specific CPU structure and operating system. When we downloaded the JRE from Sun, we saw different versions. There are some APIs (such as awt, swing, etc.) that make up the JRE together with the JVM. ), JRE is essential for running Java programs.
3. JDK -- java development kit
JDK is a java development kit. Basically, everyone who learns java will install a JDK on the machine first. What parts does it include? Let's take a look at the JDK installation directory. There are six folders, a src class library source code package, and several other declaration files under the directory. Among them, the four folders that really work when running java are bin, include, lib, and 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: the header files used by java and JVM to interact
lib: class library
jre: java runtime environment
(note: the bin and lib folders here and the bin and lib in jre are Different) In general, JDK is used for the development of java programs, while jre can only run classes without compiling.
Eclipse, idea and other IDEs have their own compilers instead of the ones in the JDK bin directory, so you will find that they only require you to select the jre path when installing.
Two and three contact
Java with the iconic slogan "Write Once, Run Anywhere (write once, run everywhere)", which is based on JRE. How to achieve this? It is to add a virtual layer - JRE between the Java application and the operating system.
The program source code is not directly compiled and linked into machine code, but first converted into a special intermediate form of bytecode (bytecode), and then the bytecode is converted into machine code or system calls. The former is a traditional compilation method, and the generated machine code is inevitably related to a special operating system and a special machine structure.
The bytecode files of Java programs can be run on any computer equipped with JRE, and then converted into corresponding machine codes by different JREs, which realizes thePortability . In this way, programmers do not have to care about the specific environment in which the program runs, and can concentrate on writing software. This idea of ​​layered abstraction and hidden details can be seen everywhere in computer science , such as the design of machine organizational structure and the implementation of network protocols. Niklaus Wirth, the inventor of the Pascal language, presciently pointed out that there should be such a portable language, which generates intermediate code that can run on a hypothetical machine.
The Java virtual machine (Java virtual machine or JVM) is such a machine, which simulates the structure of an actual processor and interprets bytecode. Why is it said to be JRE at one time and JVM at another time? Are the two the same thing and different names? The answer is no.
The status of JRE is like a PC. Win32 applications we write need the operating system to help us run them. Similarly, the Java programs we write also need JRE to run.
To run an Applet, the client must have JRE installed, that is, "runtime", which is easier to understand, just like the so-called "plug-in", to develop JAVA applications\Web applications, you must install the corresponding JVM+JDK on the server side (When developing and applying Java web applications, the client does not need to install any JVM).
If you use JAVA to develop applications, you need to install JRE+JDK, which is J2SE. 
If you run Applet on the client, the client browser must be embedded with JAVA JVM, if not, needs to be installed, that is: Create JRE on the client (runtime, including JVM), and the client does not need to be developed, so there is no need to install JDK.

Different versions of Applet may not run normally under different JVMs, and Microsoft JVM is just a "low version" of Sun JVM, Microsoft simply removed the JVM in windows xp/2003.

Guess you like

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