What is The Difference Between Java JRE and JDK?

Source: Internet
Author: User
Keywords java jdk vs jre jdk and jre in java what is jvm jre and jdk
1. Definition
JRE (Java Runtime Enviroment) is the runtime environment of Java. For users of Java programs, not developers. If you only download and install JRE, then your system can only run Java programs. JRE is a collection of environments necessary for running Java programs, including JVM standard implementation and Java core class libraries. It includes the Java virtual machine, Java platform core classes and supporting files. It does not contain development tools (compilers, debuggers, etc.).
Alibaba Cloud Simple Application Server:  Anti COVID-19 SME Enablement Program
$300 coupon package for all new SMEs and a $500 coupon for paying customers.

JDK (Java Development Kit), also known as J2SDK (Java2 Software Development Kit), is a Java development kit. It provides a Java development environment (provides a compiler javac and other tools for compiling java files into class files) and runs Environment (provides JVM and Runtime auxiliary packages for parsing class files to make them run). If you download and install the JDK, you can not only develop Java programs, but also have a platform for running Java programs. JDK is the core of Java, including Java Runtime Environment (JRE), a bunch of Java tools tools.jar and Java standard class library (rt.jar).

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

Remember to set the jdk/bin path in the environment variable path? The teacher will tell you that if you don't set it, javac and java won't work. Indeed the jdk/bin directory contains all the commands. But has anyone thought that the java command we use is not in the jdk/bin directory but in the jre/bin directory? If you don’t believe me, you can do an experiment. You can cut the java.exe in the jdk/bin directory to another place and run the java program. What do you find? Everything is OK! (There is no javac command in JRE, the reason is very simple, it is not a development environment) So someone will ask? I obviously did not set the jre/bin directory to the environment variable? Imagine if java is for most people to use, they don’t need jdk for development, only jre is needed to make the java program run, then how troublesome would each customer need to manually set environment variables? So when installing jre, the installer automatically added jre's java.exe to the system variables for you. The verification method is very simple. Go to Windows/system32 and have a look. What did you find? There is a java.exe.

3. Difficulties
If you have installed the JDK, you will find that your computer has two sets of JRE, one is located in C:\Program Files\Java\jre6, and the other is 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. Similarly, the Java programs we write must also be run by JRE. So after you install the JDK, if you install two JREs in two different places on the hard disk, then 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 run Java applications correctly.

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

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

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

If you rename 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 will be displayed:

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

java -cp C:\Program Files\Java\jdk1.6.0_41\lib\tools1.jar com.sun.tools.javac.Mainx
Will get the same result as javac.exe.

From here we can prove that javac.exe is just a wrapper, and the purpose of making it is to prevent developers from typing too long instructions.

And we can find that the programs in the C:\Program Files\Java\jdk1.6.0_41\bin directory are very small, no more than 29K. From this we can draw a conclusion. That is, the tools in the JDK are almost written in Java, so they are also Java applications. Therefore, to use the tools attached to the JDK to develop Java programs, you must also attach a set of JRE yourself, so it is located in C:\Program Files\ The JRE in the Java\jdk1.6.0_41\jre directory is used to run general Java programs.

2. If two or more JREs are installed on a computer, who decides?

This major task falls on java.exe. The job of java.exe is to find a suitable JRE to run Java programs. java.exe searches for JRE in the following order: is there a JRE in its own directory; is there a JRE in the parent directory; query the registry:

[HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment]
So the running result of java.exe has a lot to do with which JRE in your computer is executed.
Related Article

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.