Home >Java >Javagetting Started >The difference between jdk and jre
The difference between jdk and jre
1. Definition
JRE (Java Runtime Enviroment) It is the running environment of Java. For users of Java programs, not developers. If you only download and install the JRE, your system can only run Java programs. JRE is a collection of environments necessary to run Java programs, including JVM standard implementation and Java core class library. It includes Java virtual machine, Java platform core classes and supporting files. It does not contain development tools (compilers, debuggers, etc.).
JDK (Java Development Kit), also known as J2SDK (Java2 Software Development Kit), is a Java development tool kit. It provides a Java development environment (provides compiler javac and other tools for compiling java files for class files) and running environment (providing JVM and Runtime auxiliary packages for parsing class files to run them). If you download and install the JDK, you can not only develop Java programs, but also have a platform to run Java programs. JDK is the core of the entire Java, including the Java Runtime Environment (JRE), a bunch of Java tools tools.jar and the Java standard class library (rt.jar).
Recommendation: "java learning"
2. Difference
JRE mainly includes: the class file of the java class library ( All are packaged into jars in the lib directory) and virtual machines (jvm.dll); JDK mainly includes: class files of the java class library (all packaged into jars in the lib directory) and comes with a JRE. So why does the JDK come with a JRE? Moreover, the client and server folders under jdk/jre/bin both contain jvm.dll (indicating that the JRE that comes with JDK has two virtual machines).
Remember to set the jdk/bin path in the environment variable path? The teacher will tell everyone that javac and java cannot be used if they are not set up. It is true that the jdk/bin directory contains all commands. But has anyone ever thought that the java command we use is not in the jdk/bin directory but in the jre/bin directory? If you don’t believe me, you can do an experiment. You can cut the java.exe in the jdk/bin directory to another place and then run the java program. What did you find? Everything is OK! (There is no javac command in JRE, the reason is simple, it is not a development environment) So someone will ask? I obviously didn't set the jre/bin directory to the environment variable? Just imagine if java is for most people to use, they don't need jdk for development. They only need jre to make the java program run. Then how troublesome is it for each customer to manually set environment variables? So when you install jre, the installation program automatically adds jre's java.exe to the system variables for you. The verification method is very simple. Go to Windows/system32 and have a look. What did you find? There is a java.exe.
3. Difficulty
If JDK is installed, your computer will have two sets of JRE (JRE itself and the JRE in the JDK). The first set has less server-side Java than the latter set. virtual machine.
(1)Why does Sun require JDK to install two sets of the same JRE? This is because there are many development tools written in Java in the JDK (such as javac.exe, jar.exe, etc.), and they are all placed in /lib/tools.jar. If we rename tools.jar to tools1.jar and then run javac.exe, the following results will be displayed: Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/javac/Main. This means that if you enter javac.exe and enter java -cp c:/jdk/lib/tools.jar com.sun.tools.javac.Main, you will get the same result. From here we can prove that javac.exe is just a wrapper (Wrapper), and the purpose of making it is to save developers from entering too long commands. And we can find that the programs in the /lib directory are very small, no larger than 29K. From here we can draw a conclusion. That is, almost all the tools in the JDK are written in Java, so they are also Java applications. Therefore, if you want to use the tools attached to the JDK to develop Java programs, you must also attach a set of JRE yourself, so the set located in the JDK directory JRE is used to run general Java programs.
(2) If more than two sets of JRE are installed on a computer, who will decide? This important task falls on java.exe. The job of java.exe is to find the appropriate JRE to run the Java program. java.exe searches for JRE in the following order: 1) Is there a JRE in its own directory; 2) Is there a JRE in the parent directory; 3) Query the registry: [HKEY_LOCAL_MACHINE/SOFTWARE/JavaSoft/Java Runtime Environment]. Therefore, the running result of java.exe has a great relationship with which JRE is executed in your computer.
(3) There are two folders in the JDK-->JRE-->Bin directory: server and client. This is where the real jvm.dll is located. jvm.dll cannot work alone. When jvm.dll is started, it will use the explicit method (that is, using LoadLibrary() and GetProcAddress() in the Win32 API to load the auxiliary dynamic link library), and these auxiliary dynamic link libraries Dynamic link libraries (.dll) must be located in the parent directory of the directory where jvm.dll is located. Therefore, which JVM you want to use, you only need to set the PATH to point to jvm.dll in the directory where the JRE is located.
4. The most mainstream JDK is the JDK released by Sun. In addition to Sun, there are many companies and organizations that have developed their own JDK, such as JDK developed by IBM, Jrocket by BEA, and There are JDKs developed by the GNU organization and so on.
The above is the detailed content of The difference between jdk and jre. For more information, please follow other related articles on the PHP Chinese website!