Basic interview questions: JDK and JRE

1. Definitions

JDK is the Java Development Kit, which is fully functional Java SDK. It has everything, as well as the compiler (javac) and JRE tools have (such as javadoc and jdb). It can create and compile the program.

JRE is the Java Runtime Environment. It is everything you need to run the compiled Java program collection, including the Java Virtual Machine (JVM), Java class libraries, java command and some other basic components. However, it can not be used to create new programs.

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).

3. Difficulties

If the JDK is installed, you will find your computer has two sets of JRE, located in a C: \ Program Files \ Java \ jre7, another set is located in C: \ Program Files \ Java \ jdk1.7.0_72 under \ jre directory.
JRE status as a PC, we write Win32 applications require the operating system to help us run the same, Java programs must also be written in our JRE to run. So when you finished loading JDK, if separately in two different places on the hard disk to install two sets of JRE, then you can imagine your computer has two virtual Java
PC machine, have a function to run Java programs. So we can say, as long as your computer to install the JRE, Java applications can be run properly.

4. problem

a, 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, these commands are placed in C: \ Program Files \ Java \ jdk1.7.0_72 \ bin directory.
Because they are written in java command, so to rely on java jar package, these jar package stored in C: \ Program Files \ Java \ jdk1.7.0_72 \ lib directory
if the C: \ Program Files \ Java \ jdk1.7.0 _72 \ lib \ directory of tools.jar renamed tools1.jar, and then run javac.exe, show the following results:
Exception in the Thread "main" java.lang.NoClassDefFoundError: COM / Sun / Tools / javac / main
but the input java -cp C: \ Program Files \ Java \ jdk1.7.0_72 \ lib \ tools1.jar com.sun.tools.javac.Main
will get the same results javac.exe.
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 we can find C: \ Program Files \ Java \ Program under jdk1.7.0_72 \ bin directory are small, no larger 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 located at C: \ Program Files \ Java \ jdk1.7.0_72 \ jre directory under the set of JRE that is used to run Java programs are generally used.

b, if a computer installed more than 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 accordance with the order of the bottom to find the JRE: there is no JRE own directory; parent directory has no JRE; to query the registry:
[HKEY_LOCAL_MACHINE \ SOFTWARE \ JavaSoft \ the Java Runtime Environment]
Therefore, operating results with your java.exe JRE is inside the computer which has a lot to perform.

Published 122 original articles · won praise 13 · views 410 000 +

Guess you like

Origin blog.csdn.net/jinxinxin1314/article/details/105422757