Easy Tutorial
❮ Android Tutorial Fragment Base Android Tutorial Gridview ❯

Differences Between JRE and JDK

Category Programming Technology

1. Definition

JRE (Java Runtime Environment) is the runtime environment for Java. It is aimed at users of Java programs, not developers. If you only download and install JRE, your system can only run Java programs. JRE is a collection of the necessary environment to run Java programs, including the standard implementation of JVM and Java core libraries. It includes the Java Virtual Machine, Java platform core classes, and support files. It does not include development tools (compilers, debuggers, etc.).

JDK (Java Development Kit), also known as J2SDK (Java2 Software Development Kit), is the Java development toolkit. It provides the development environment for Java (providing tools such as the compiler javac, which is used to compile java files into class files) and the runtime environment (providing JVM and Runtime auxiliary packages to parse class files for execution). If you download and install JDK, you can not only develop Java programs but also have the platform to run Java programs. JDK is the core of the entire Java, including the Java runtime environment (JRE), a set of Java tools (tools.jar), and the Java standard library (rt.jar).

2. Differences

JRE mainly includes: Java library class files (all packaged into jar in the lib directory) and the virtual machine (jvm.dll); JDK mainly includes: Java library class files (all packaged into jar in the lib directory) and comes with a JRE. So why does JDK come with a JRE? And why does the client and server folders under jdk/jre/bin both contain jvm.dll (indicating that the JRE that comes with JDK has two virtual machines)?

Remember setting the jdk/bin path in the environment variable? Teachers will tell everyone that if it is not set, javac and java cannot be used. Indeed, the jdk/bin directory contains all the commands. But has anyone ever thought that the java command we use is not under the jdk/bin directory but under the jre/bin directory? If you don't believe it, you can try an experiment. You can cut the java.exe in the jdk/bin directory to another place and run the Java program. What did you find? Everything is OK! (There is no javac command in JRE, the reason is simple, it is not a development environment) So someone will ask? I didn't set the jre/bin directory in the environment variable? Imagine if Java is provided for most people to use, they don't need jdk for development, they just need jre to run Java programs, then each customer still needs to manually set the environment variable, how troublesome! So when installing jre, the installation program automatically adds the java.exe of jre to the system variable for you. The verification method is very simple, go to Windows/system32 and see what you find? There is a java.exe.

3. Difficulties

If JDK is installed, you will find that your computer has two sets of JRE, one located at C:\Program Files\Java\jre6, and the other located in the C:\Program Files\Java\jdk1.6.0_41\jre directory.

The status of JRE is like a PC. The Win32 applications we write need the operating system to help us run, and the same is true for the Java programs we write. They must have JRE to run. So when you install JDK, if you install two sets of JRE in two different places on the hard disk, you can imagine that your computer has two virtual Java PCs, both of which have the function of running Java programs. So we can say that as long as your computer has JRE installed, you can correctly run Java applications.

1. Why does Sun let JDK install two sets of the same JRE?

This is because there are many development tools written in Java in JDK, such as javac.exe, jar.exe, etc., which are placed in the C:\Program Files\Java\jdk1.6.0_41\bin directory.

Because they are Java-written commands, they rely on Java jar packages, which are stored in the C:\Program Files\Java\jdk1.6.0_41\lib directory.

If you rename the tools.jar in the C:\Program Files\Java\jdk1.6.0_41\lib directory to tools1.jar, and then run javac.exe, the following result is displayed:

Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/javac /Main

But if you enter:

``` java -cp C:\Program Files\Java\jdk1.6.0_

❮ Android Tutorial Fragment Base Android Tutorial Gridview ❯