First, Detailed introduction1. JVM-Java Virtual machineThe JVM is what we often call Java virtual machine, it is the entire Java implementation cross-platform of the most core part, all Java programs will be compiled into a. class file, which can be executed on the virtual machine, that is, class is not directly related to the machine's operating system, Instead, the virtual machine interacts with the operating system indirectly, and the virtual machine interprets the program to the local system for execution.The JVM is the foundation of the Java platform, which, like the actual machine, has its own set of instructions and operates in different memory areas at runtime. By abstracting the operating system and CPU structure, the JVM provides a platform-independent code execution method that is independent of the special implementation method, host hardware, and host operating system. But in some small ways, the implementation of the JVM is not the same, such as garbage collection algorithm, thread scheduling algorithm (perhaps different OS have different implementations).The main task of the JVM is to explain its own set of instructions (that is, bytecode) to the CPU's instruction set or OS system calls to protect the user from malicious program harassment. The JVM does not care about the upper Java source files, it only focuses on the class file generated by the source file. The composition of the class file includes the JVM instruction set, the symbol table, and some subsidy information.2. JRE-Java Runtime EnvironmentThe JRE refers to the Java Runtime environment. The JVM cannot be executed as a class, because the JVM needs to invoke the class library lib that is needed to interpret the classes. In the JDK installation directory you can find the JRE directory, there are two folders Bin and Lib, here you can think that the bin is Jvm,lib is the JVM to work the class library, and the JVM and Lib are called the JRE. So, after you've finished compiling the Java program into. class, you can package the. class file with the JRE and send it to your friends so that your friends can run your program. (There are java.exe running. Class in the JRE)The JRE is a larger system released by Sun, and it has a JVM inside it. The JRE is related to the specific CPU structure and operating system, and we see different versions when we download the JRE from Sun. There are also APIs (such as AWT, swing, and so on) that make up the JRE together with the JVM. The JRE is essential for running Java programs.JRE (Java Runtime Environment) is essential for running Java programs (unless compiled into an. exe executable with some other compiled environment ...). ), the JRE is like a PC, and our WIN32 application requires the operating system to run it, and the Java program we write must also have the JRE to run.There is a JVM in the JRE, the JRE is related to the specific CPU structure and operating system, we see different versions when we download the JRE from Sun, and there are some APIs (such as AWT, swing, etc.) that make up the JRE together with the JVM, and the JRE is running Java programs are essential.3. JDK--Java Development KitThe JDK is the Java SDK, and basically everyone who learns Java will first have a JDK on the machine, which part does he include? Let's take a look at the JDK installation directory. Under the directory there are six folders, a SRC class library source code compression package, and several other declaration files. One of the four folders that really worked when running Java was the following: Bin, include, Lib, JRE. Now we can see a relationship where the JDK contains the JRE, and the JRE contains the JVM.Bin: The main thing is the compiler (Javac.exe)Include:java header files for interaction with the JVMLIB: Class LibraryJre:java Operating Environment(Note: The bin, Lib folder and the bin in the JRE, Lib is different) in general, the JDK is used for the development of Java programs, and the JRE is only to run class and not compiled functionality.Other Ides such as Eclipse, idea, and so on have their own compilers instead of the JDK bin directory, so you'll find them only asking you to check the JRE path when installing.Two, three contactJava's iconic slogan, "Write Once, run anywhere (once written, running everywhere)" is built on the JRE. How is it achieved? Is the addition of a virtual layer--jre between the Java application and the operating system.The program source code is not directly compiled, linked to machine code, but first converted to bytecode (bytecode) This special intermediate form, bytecode conversion to machine code or system call. The former is a traditional compiling method, and the generated machine code is inevitably related to the special operating system and the special machine structure.The Java program's bytecode files can be placed on any of the installed JRE of the computer to run, and then by the different JRE into the corresponding machine code, which enables the Java program portability. In this way, programmers do not have to care about the specific environment in which the program runs, but can concentrate on writing software. The idea of layered abstraction and hidden detail is visible in computer science, such as the design of machine organization structure and the realization of network protocol. Niklaus Wirth, the inventor of the Pascal language, predictably pointed out that there should be a portable language in which the intermediate code generated could run on an imaginary machine (a hypothetical machines).the Java Virtual machine (Java VM or JVM) is one such machine that simulates the structure of the actual processor and interprets the bytecode. How can one say that it is the JRE, and then it becomes the JVM, and are the two different names? The answer is in the negative. The JRE is like a PC, and our WIN32 application requires the operating system to run it, and the Java program we write must also have the JRE to run. to run applets, the client must have a JRE installed, or "runtime", which is easy to understand, like so-called "plug-ins", to develop Java application \web applications, you must install the appropriate JVM+JDK on the server side (when developing Java Web applications, The client does not need to install any JVM) if you are using Java to develop your application, you will need to install JRE+JDK, which is J2SE. If the applet is run on the client, the client browser must have a Java JVM embedded, and if not, it needs to be installed, that is, the JRE is created on the client (runtime, including the JVM), and the client does not need to be developed, so the JDK is not necessary to install it. different versions of applets may not work properly under different JVMs, and Microsoft JVM is just the "low version" of the Sun JVM, and Microsoft simply removes the JVM from Windows xp/2003.
The difference between JRE and JVM, JDK