1, JVM-java virtual machine
JVM is what we often call java virtual machine. It is the core part of the whole java cross-platform implementation. All java programs will be compiled into. First, the class file can be executed on the virtual machine, that is, 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 releases the program to the local system for execution.
JVM is the foundation of Java platform. Like a real machine, it has its own instruction set and operates different memory areas at runtime. JVM provides a platform-independent code execution method by abstracting the operating system and CPU structure, that is, independent of specific implementation methods, host hardware and host operating system. But in some small aspects, the implementation of JVM is also different, such as garbage collection algorithm and thread scheduling algorithm (different OS may have different implementations).
The main job of JVM is to explain its instruction set (that is, bytecode) to the instruction set of CPU or the system call of OS, thus protecting users from the interference of malicious programs. The JVM doesn't care about the upper Java source files, only the class files generated by the source files. The class file consists of JVM instruction set, symbol table and some subsidy information.
2. JRE-java runtime environment
JRE refers to the java runtime environment. JVM alone cannot be executed as a class, because JVM needs to call the class library lib needed for interpretation when interpreting classes. In the installation directory of JDK, you can find the jre directory, which contains two folders, bin and lib. It can be thought that bin is jvm, lib is the class library needed by jvm, and jvm and lib together are called jre. So, now you write a java program and compile it into. Students, you can pack this. Class file and send it to your friends, so that your friends can run your program. (java.exe is running. Classes in jre)
JRE is a larger system released by Sun Company, which includes a JVM. JRE is related to a specific CPU structure and operating system. When we downloaded JRE from Sun, we saw different versions. There are some APIs (such as awt, swing, etc. ) use JVM to form JRE. JRE is essential for running Java programs.
JRE (Java Runtime Environment) is essential for running Java programs (unless it is compiled into. Exe executable files are compiled by some other compilation environments ...). JRE is like a PC. The Win32 application we wrote needs the operating system to help us run. Similarly, the Java programs we write also need JRE to run.
There is a JVM in JRE, which is related to the specific CPU structure and operating system. When we downloaded JRE from Sun, we saw different versions. There are also some APIs (such as awt, swing, etc. Together with the JVM, it forms the JRE. JRE is essential for running Java programs.
3. JDK-java Development Toolkit
JDK is a java development toolkit. Basically everyone who learns java will install a JDK on the machine first. What parts does it contain? Let's take a look at the JDK installation directory. There are six folders in the directory, one src class library source code compressed package, and several other declaration files. Among them, what really works when running java are the following four folders: bin, include, lib and jre. Now we can see the relationship between JDK containing JRE and JRE package containing JVM.
Bin: The most important thing is the compiler (javac.exe).
Contains: the header file of the interaction between Java and JVM.
Lib: class library
Jre:java runtime environment
(Note: bin and lib folders here are different from those in jre.) Generally speaking, JDK is used for the development of java programs, while jre can only run class and cannot compile.
Ides such as Eclipse and idea all have their own compilers, not those in JDK bin directory, so you will find that they only need you to select the jre path when installing.
Second, the three links
The iconic slogan "Write Once, Run Anywhere" shouted by Java is based on JRE. How to achieve it? It adds a virtual layer-JRE between Java application and operating system.
The program source code is not directly compiled and linked into machine code, but first converted into byte code, a special intermediate form, and then converted into machine code or system call. The former is a traditional compiling method, and the generated machine code must be related to the special operating system and special machine structure.
Byte code files of Java programs can be put into any computer with JRE, and then converted into corresponding machine code by different JRE, which realizes the portability of Java programs. In this way, programmers don't have to care about the specific environment in which the program runs, and can concentrate on writing software. This idea of layered abstraction and hiding details can be seen everywhere in computer science, such as the design of machine organization structure and the realization of network protocol. Niklaus wirth, the inventor of Pascal, predicted that there should be such a portable language, and the intermediate code generated by it can run on an imaginary machine.
Java virtual machine (Java Virtual Machine or JVM) is such a machine, which simulates the structure of the actual processor and interprets bytecode. Why talk about JRE for a while and JVM for a while? Are they the same thing with different names? The answer is no.
JRE is like a PC. The Win32 application we wrote needs the operating system to help us run. Similarly, the Java programs we write need JRE to run.
To run Applet, JRE, or "runtime", must be installed on the client, which is easy to understand. Just like the so-called "plug-in", to develop a JAVA application \Web application, the corresponding JVM+JDK must be installed on the server side (when developing a Java web application, the client does not need to install any JVM).
If you develop an application in JAVA, you need to install JRE+JDK, which is J2SE.
If you run the Applet on the client, the client browser must embed the JAVA JVM. If not, you need to install it, that is, create a JRE (including the JVM at runtime) on the client, and the client does not need to develop, so you don't need to install JDK.
Different versions of Applet may not run normally under different JVMs, while Microsoft JVM is just a "low-end version" of Sun JVM, and Microsoft just removed the JVM in windows xp/2003.