The difference between jdk and jre is vivid clear and easy to understand

  • 2020-05-09 19:03:20
  • OfStack

Simply put, JDK is SDK for developers. It provides both the development environment and the runtime environment for Java. SDK is an Software Development Kit 1 software development package, which can include function libraries, compilers, etc.
JDK is Java Development Kit
JRE is Java Runtime Enviroment refers to the Java operating environment, is for Java application consumers, not developers.

If you have installed JDK, you will receive two sets of JRE, one set in C:\Program Files\Java\ j2re1.4.1_01, the latter set is less Server Java virtual machine, but just copy the former set of Server Java virtual machine. And when installing JDK, you can choose whether or not to install JRE located in the C:\Program Files\Jav a directory. If you only install JRE, not JDK, then only 1 set of JRE with only 1 will be installed in C:\Program Files\Java.

JRE is like an PC machine. The Win32 application we wrote needs to be run by the operating system, and the Java application we wrote needs to be run by JRE. So when you've installed JDK, if you've installed two JRE units in two different places on your hard drive, you can imagine that your computer has two virtual Java PC machines, both of which are capable of running Java programs. So we can say that as long as you have JRE installed on your computer, you can run the Jav a application correctly.

1. Why does Sun want JDK to install two identical JRE units? This is because JDK contains many development tools written in Java (javac.exe, jar.exe, etc.) and they are all placed in \lib\ tools.jar. As you can see from the following example, first rename tools.jar to tools1.jar, and then run javac.exe to display the following results: Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/javac/Main this mean, you enter javac. exe input java - cp c: \ jdk \ lib \ tools jar com. sun. tools. javac. Main is 1 kind, will get the same results. From here we can prove that javac.exe is just a wrapper (Wrapper) and was made to save developers from typing too long fingers. Moreover, it can be found that the programs in the directory \lib are all small, no larger than 2 9K. From here, we can draw a conclusion. The JDK tool is almost written in Java, so it is also an Java application. To develop Java using the JDK attached tool, you must also attach a set of JRE, so the JRE in C:\Program Files\Java directory is used to run the Java program.

2. If more than two sets of JRE are installed on one computer, who will decide? That task falls to java.exe. Java.exe's job is to find the right JRE to run the Java program. Java.exe looks for JRE in the order below: is JRE in your own directory? Parent directory has no JRE; Query registry: [HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment] so java.exe has a lot to do with which JRE is executed on your computer.

The Bin directory under JVM JRE has two directories: server and client. This is the real jvm.dll. jvm.dll does not work alone. When jvm.dll is started, the explicit method (LoadLibrary() and GetProcAddress() in Win32 API are used to load the helper dynamic link libraries (.dll) that must be in the parent directory of the directory where jvm.dll is located) is used. So which JVM to use, just set PATH, pointing to jvm.dll at the bottom of the directory where JRE is located.

Related articles: