Many programmers have been working on Java for a while and still do not understand the difference between JDK and JRE.
·JDK is the Java Development Kit. In short, JDK is an SDK for developers. It provides the Java development environment and runtime environment. The SDK is a software development kit. It generally refers to a software development kit, which can include function libraries and compiled programs.
·JRE is the Java runtime enviroment, which refers to the Java Runtime Environment and is intended for Java program users rather than developers.
·If JDK is installed, there will be two sets of JRE on your computer, one in the \ JRE and the other in the c: \ Program Files \ Java \ jre1.5.0 _ 15 directory, this later set is less server-side Java virtual machine than the previous one, but simply copy the previous server-side Java virtual machine. In addition, you can choose whether to install
C: \ Program Files \ JRE under the Java directory. If you only install JRE instead of JDK, only a unique set of JRE will be installed in the c: \ Program Files \ Java directory.
·The status of JRE is just like that of a PC. The Win32 application we write requires the operating system to help us run it. Similarly, the Java program we write must also run JRE. So after installing JDK, if two sets of JRE are installed in two different locations on the hard disk, you can imagine that your computer has two virtual Java
PC has the function of running Java programs. So we can say that if your computer has installed JRE, you can run the Java application correctly.
1. Why does Sun need JDK to install two identical JRE?
This is because many Java-compiled development tools (such as javac.exe‑jar.exe) are used in JDK, and are stored in \ Lib \ tools. jar.
. As shown in the following example, change tools.jarto tools1.jarand run javac.exe. the following result is displayed: exception in thread "Main" Java. lang. noclassdeffounderror: COM/Sun/tools/javac/Main. You can input javac.exe and Java-CP c: \ JDK \ Lib \ tools. jar COM. sun. tools. javac. the main is the same and the same result is obtained. From this we can prove that javac.exe is just a wrapper, and the purpose is to prevent developers from entering too long fingers. In addition, we can find that the programs in the \ lib directory are very small, not greater than 2.
9 K. Here we can draw a conclusion. That is, JDK tools are almost written in Java, so they are also Java applications. Therefore, to use the tools attached to JDK to develop Java programs, you must also attach a set of JRE, therefore, the JRE located in the c: \ Program Files \ Java directory is used to run general Java programs.
2. If two or more JRE are installed on a computer, who will decide?
This major 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: whether JRE is in its Directory; whether JRE is in its parent directory; Query registry: [HKEY_LOCAL_MACHINE \ SOFTWARE \ javasoft \ Java Runtime
Environment] The running result of java.exe has a lot to do with which JRE is executed on your computer.
Add :( small summary)
1. JVM-- Java virtual machinejvm is the most common Java virtual machine. It is the core of cross-platform JAVA Implementation. All Java programs are first compiled. class files, which can be executed on virtual machines. That is to say, the class does not directly correspond to the operating system of the machine, but indirectly interacts with the operating system through the Virtual Machine, the Virtual Machine interprets the program to the local system for execution.
2. JRE-- Java runtime environmentjre refers to the Java Runtime Environment. JVM alone cannot be executed as a class, because the JVM needs to call the library lib required for explanation when interpreting the class. In the JDK installation directory, you can find the JRE Directory, which contains two folders bin and Lib. Here we can think that the bin contains JVM, And the Lib is the class library required for JVM work, while JVM and
Lib is called JRE. Therefore, after you compile the Java program into a. Class file, you can package the. Class file with JRE to your friends so that your friends can run your program. (Jrehas java.exe running .class)
3. JDK-- Java Development kitjdk is a Java Development Kit. Basically, everyone who learns Java will first install a JDK on the machine. Which part does it contain? Let's take a look at the JDK installation directory. The directory contains six folders, one SRC Class Library source code package, and several other declaration files. Specifically, the following four folders actually work when running Java: Bin, include, Lib,
JRE.Now we can see that JDK contains JRE, and JRE contains JVM.
- Bin: the most important part is the compiler (javac.exe)
- Include: header file for Java and JVM Interaction
- Lib: Class Library
- JRE: Java Runtime Environment (Note: The bin and Lib folders here are different from the bin and Lib in JRE)
In general, JDK is used for Java program development, while JRE can only run class files, which has no compilation function.
Other ides such as Eclipse and idea have their own compilers instead of those embedded in the JDK bin directory. Therefore, during installation, you will find that they only require you to select the JRE path.
Reprinted from: http://www.cnblogs.com/myitm/archive/2011/05/03/2035942.html