Programmer: I only know the difference and connection between JDK and JRE today!

Everyone knows JDK and JRE, but if the interviewer asks "what does JDK do", "what does JRE do", "what is the difference between the two" and other questions, it may not be answered. The following mainly talks about the difference and connection between JDK and JRE.
Without further ado, the first picture:
Insert picture description here
From the picture above, it can be seen that the JDK is the core of the entire JAVA, including the Java runtime environment JRE (Java Runtime Envirnment), a bunch of Java development tools (javac / java / jdb, etc.) and Java foundation The class library (that is, Java API package), the following begins to demystify the JDK and JRE.


1. Concept

JDK is called Java Development Kit, and as its name implies, it is a Java development kit. It is a development kit needed by programmers to write java programs using java language.

JRE is called Java Runtime Environment. As the name implies, it is a Java runtime environment. It contains a Java virtual machine and a Java basic class library. It is a software environment required for programs written in Java to run.

Second, the difference

1. Different for the crowd

JDK is provided to programmers. JRE is provided for users who want to run java programs.

2. Different importance levels
If you need to write java programs, you need to install JDK. If you need to run a java program, just install JRE.

3. The installation directory is different
3.1. If the JDK is installed, the computer will have two sets of JRE

One set is the JRE in the JDK, located in the \ jre directory.
The other set is JRE's own, and it is located in the C: \ Program Files \ Java \ jre directory by default during download and installation.
Here, the blogger put it in the D drive when installing JRE, as shown in the figure:
(1) E: \ Java \ jre
Insert picture description here
(2) D: \ Java \ jre
Insert picture description here
3.2. If only JRE is installed, it will default to C: \ Program Files The only set of JRE is installed under the \ Java directory, the location can be selected, here the blogger put it on the D drive:
Insert picture description here
three, contact

1. Contains the relationship
JDK includes JRE, and also includes the compiler javac that compiles the java source code, and also includes many tools for debugging and analyzing java programs (JConsole, Web Services and other tool software), and also includes a Java-based class library (That is, the Java API includes rt.jar).

2. Execution relationship
First of all, the JVM is mentioned here. JVM (Java Virtual Machine) is the java virtual machine we often say. It is the core part of the entire java implementation cross-platform. All java programs will be compiled as .Class class file, this class file can be executed on the virtual machine.
In other words, 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.
Only the JVM cannot be executed as a class, because when interpreting a class, the JVM needs to call the library lib required by the interpretation, and jre contains the lib library. In the jre directory under the JDK, there are two folders bin and lib. Here you can think that the bin is the jvm, and the lib is the class library needed for the jvm to work, and the jvm and lib are called jre.

得到公式:jvm+lib=jre

jvm in the bin directory
JVM class in lib
The JVM shields information related to specific operating system platforms, so that Java programs only need to generate the target code (byte code) that runs on the Java virtual machine and can run on multiple platforms without modification.

All in all, after we developed our own JAVA program using JDK (calling JAVA API), we compiled our text java file into JAVA bytecode through the compiler (javac) in the JDK and run these JAVA bytes on JRE Code, the JVM parses these bytecodes and maps them to the CPU instruction set or OS system calls.

Perfection is achieved not when you have nothing more to add, but when you have nothing left to take away.—— Antoine de Saint-Exupery

Published 40 original articles · Liked 113 · Visits 7648

Guess you like

Origin blog.csdn.net/qq_42257666/article/details/105701938