The difference between JDK and JRE

Source: Internet
Author: User

Many programmers have been working on Java for some time and still don't understand the difference between JDK and JRE.
the JDK is Java development Kit. To put it simply, the JDK is a developer-oriented SDK that provides a Java development environment and a running environment. The SDK is software Development Kit generally refers to a software development package, which can include function libraries, compiler programs, and so on.
The JRE is Java runtime enviroment, which refers to the Java Runtime Environment, and is intended for users of Java programs, not developers.
If the JDK is installed, there will be two sets of JRE on your computer, one in the \jre and one in the C:\Program files\java\jre1.5.0_15 directory, and the other Java virtual machine, which is less server-side than the previous set. But just copy the server-side Java Virtual machine in front of you. You can also choose whether to install the JRE in the C:\Program Files\java directory when installing the JDK. If you install only the JRE, not the JDK, only a single set of JRE will be installed in the C:\Program Files\java directory.
The JRE is like a PC, and our WIN32 application requires the operating system to run it, and the Java program we write must also have the JRE to run. So when you're finished installing the JDK, if you have two sets of JRE installed in two different places on your hard drive, you can imagine your computer has two virtual Java PCs, all with the ability to run Java programs. So we can say that if you have a JRE installed on your computer, you can run Java applications correctly.
1. Why does Sun want to have the JDK install two identical JRE?

This is because the JDK has a lot of Java-written development tools (such as Javac.exe, Jar.exe, etc.), and is placed in the \lib\tools.jar. As can be seen from the following example, first renamed Tools.jar to Tools1.jar, and then run Javac.exe, showing the following result: Exception in thread "main" Java.lang.NoClassDefFoundError: Com/sun/tools/javac/main This means that your input javac.exe is the same as the input JAVA-CP C:\jdk\lib\tools.jar Com.sun.tools.javac.Main and will get the same result. From here we can prove that Javac.exe is just a wrapper (Wrapper), and the purpose of the production is to keep the developer from entering too long a finger. And can find the \lib directory of the program is very small, not more than 2 9K, from here we can draw a conclusion. Is that the tool in the JDK is almost written in Java, so it is also a Java application, so to use the tools attached to the JDK to develop Java programs, you must also attach a set of JRE, so it is located in C:\Program files\ The JRE in the Java directory is used to run generic Java programs.

2, if a computer installed more than two sets of JRE, who will decide?
The big task falls on Java.exe. Java.exe's job is to find the right JRE to run Java programs. Java.exe the JRE according to the following order: There is no JRE in its own directory; the parent directory has no JRE; query registry: [Hkey_local_machine\software\javasoft\java Runtime Environment] So Java.exe's running results have a lot to do with which JRE in your computer is being executed.

ADD: (small summary)

1.JVM-Java Virtual MACHINEJVM is what we often call Java VMS, which is the most central part of the entire Java implementation across platforms, All Java programs are first compiled into a. class file, which can be executed on a virtual machine, which means that class does not correspond directly to the machine's operating system, but instead interacts with the operating system indirectly by the virtual machine, which interprets the program to the local system for execution.

2.JRE--Java Runtime environmentjre refers to the Java operating environment. The JVM cannot be executed as a class, because the JVM needs to invoke the class library lib that is needed to interpret the classes. In the JDK installation directory you can find the JRE directory, there are two folders Bin and Lib, here you can think that the bin is Jvm,lib is the JVM to work the class library, and the JVM and Lib are called the JRE. So, after you've finished compiling the Java program into. class, you can package the. class file with the JRE and send it to your friends so that your friends can run your program. (There is a java.exe in the JRE running. Class)

3.JDK--Java development kitjdk is the Java SDK, basically everyone who learns Java will first install a JDK on the machine, which part does he include? Let's take a look at the JDK installation directory. Under the directory there are six folders, a SRC class library source code compression package, and several other declaration files. One of the four folders that really worked when running Java was the following: Bin, include, Lib, JRE. Now we can see a relationship where the JDK contains the JRE, and the JRE contains the JVM. Bin: The main thing is the compiler (Javac.exe) Include:java and JVM interaction with the header file Lib: Class library Jre:java operating Environment (note: Here the bin, Lib folder and the bin in the JRE, Lib is different) in general the JDK is used for Java program development, while the JRE is a function that can only run class without compiling.

other Ides such as Eclipse, idea, and so on have their own compilers instead of the JDK bin directory, so you'll find them only asking you to check the JRE path when installing.

The difference between JDK and JRE

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.