What is the difference between JRE and JDK?

Reprinted from: http://www.pinlue.com/article/2020/03/0508/089982919333.html

 

1. Definitions

JRE (Java Runtime Enviroment) is a Java runtime environment. Java programs for users, not developers. If you download and install the JRE only, then your system can run Java programs. JRE is a set of necessary environment to run Java programs, including JVM Java core libraries and standard implementation. It includes the Java Virtual Machine, Java platform core classes and supporting files. It does not include development tools (compiler, debugger, etc.).

JDK (Java Development Kit), also known as J2SDK (Java2 Software Development Kit), the Java Development Kit, which provides a Java development environment (provided javac compiler and other tools for java files compiled into class files) and run environment (Runtime provides JVM and auxiliary package for parsing the class file to get it to run). If you download and install the JDK, then you can not only develop Java programs, also have a platform to run Java programs. It is the core Java JDK, including the Java Runtime Environment (JRE), and a bunch of Java tools tools.jar Java standard class library (rt.jar).

2. Distinction

JRE mainly includes: java library class files (both packaged into jar in the lib directory) and virtual machines (jvm.dll); JDK mainly includes: java library class files (both packaged into jar in the lib directory ) and comes with a JRE. So why should JDK comes with a JRE it? And the next client and server under jdk / jre / bin folder contains two jvm.dll (JDK that comes with JRE instructions have two virtual machines).

Remember to set jdk / bin path environment variable path in it? The teacher will tell you not set, then javac and java is not take. Indeed jdk / bin directory contains all commands. But has anyone thought java command does, but we are not under jre under the jdk / bin directory / bin directory? Do not believe you can do an experiment, we can cut the java.exe under the jdk / bin directory to somewhere else and then run java program, to find anything? Everything OK! (JRE is not javac command, the reason is very simple, it is not a development environment) someone is bound to ask? I obviously do not set jre / bin directory to environment variable ah? Imagine if java in order to provide most people use, they do not need jdk development, just let jre java program up and running on it, so each customer need to manually set the environment variable much trouble ah? So jre installed when you install the program automatically help add to the java.exe jre of system variables, verification method is very simple, go to Windows / system32 below go and see what was found? There is a java.exe.

3. Difficulties

If the JDK is installed, your computer will have two sets of JRE (JRE JRE and JDK itself in), set in front of fewer Server-side Java virtual machine behind the set ratio.

(1) Why let the Sun JDK JRE installed two sets of the same? This is because there are a lot JDK written in Java development tools (such as javac.exe, jar.exe, etc.), and are placed in /lib/tools.jar years. If we tools.jar renamed tools1.jar, and then run javac.exe, show the following results: Exception in thread "main" java.lang.NoClassDefFoundError: com / sun / tools / javac / Main. This means that you enter javac.exe input java -cp c: /jdk/lib/tools.jar com.sun.tools.javac.Main is the same, will get the same results. From here we can prove javac.exe just a wrapper (Wrapper), while making purpose is to allow developers from having to enter long fingers life. And the program can be found in the / lib directory is very small, not more than 29K, from here we can draw a conclusion. Is the JDK tools is almost written in Java, it is also a Java application, so use JDK accompanying tools to develop Java programs, must also attach themselves to a JRE for the job, so the set is located in the JDK directory JRE is generally used to run Java programs.

(2) If more than one computer installation of two sets of JRE, who decides it? The major task falls java.exe body. java.exe job is to find a suitable JRE to run Java programs. java.exe in the following order to find the JRE: 1) under its own directory has no JRE; 2) the parent directory has no JRE; 3) query the registry: [HKEY_LOCAL_MACHINE / SOFTWARE / JavaSoft / Java Runtime Environment]. So run with java.exe results inside your computer which has a great relationship JRE is executed.

(3) JDK -> JRE -> There are two folders Bin directory: server and client, this is the real jvm.dll lies. jvm.dll can not work alone, when jvm.dll starts, using explicit methods (using LoadLibrary is among the Win32 API () and GetProcAddress () to load with the aid of dynamic link library), which assisted with the dynamic-link library (.dll) must be located in the directory of the parent directory jvm.dll. So what you want to use JVM, only you need to set the PATH, where the next point jvm.dll JRE directory.

4. The most mainstream JDK is Sun's release of JDK, in addition to the Sun, there are many companies and organizations have developed their own JDK, for example, developed by IBM JDK, BEA's Jrocket, as well as organizational development of GNU JDK and many more.

Published 60 original articles · won praise 52 · views 110 000 +

Guess you like

Origin blog.csdn.net/yihuliunian/article/details/104671976