Differences between JDK JRE

Source: Internet
Author: User

The tools in DK are also written in Java. They also need a set of JRE when running, such as the JRE under the C:/program files/Java/jdk1.5.x/directory. The JRE in the C:/program files/Java/directory is used to execute our own Java program. Of course, any of the two sets of JRE can be used to execute our own Java program, but the tools in JDK can only be set by C: run the jre in the/program files/Java/jdk1.5.x/directory.

That is to say
JDK (Java Development Kit) is a development kit, equivalent to a compiler.
JRE (Java Runtime Environment) is the runtime environment, equivalent to the JVM virtual machine. The Java program developed by JDK must run in JVM, and JRE provides such an environment.
----------------------------------------------------------------------------

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 in 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. After installing JDK, you can choose whether to install the JRE in the C:/program files/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 PCs, all have 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 JDK has a lot of Java-compiled development tools (such as javac.exe‑jar.exe), and they are all 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, the JDK tool is almost written in Java, so it is also a Java application. Therefore, to use the tool attached to JDK to develop Java programming, you must also attach a set of JRE, therefore, the set of 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 own directory; whether JRE is in its parent directory; and query the registry: [HKEY_LOCAL_MACHINE/software/kerberoft/Java Runtime Environment] The running result of java.exe is closely related to which JRE is executed on your computer.

Add :( small summary)

1. JVM -- Java Virtual Machine
JVM is what we often call a 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 Environment
JRE 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, JVM and Lib are 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 Kit
JDK is a Java Development Kit. Basically, everyone who learns Java will first install a JDK on the machine. What components does JDK contain? Let's take a look at the JDK installation directory. The directory contains six file clips, a SRC Class Library source code compressed package, and several other declaration files. The following four folders are actually used when running Java: Bin, include, Lib, and 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, lib folder and bin and Lib in JRE are different.) In general, JDK is used for Java program development, JRE can only run the class without compiling.

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.

-----------------------------------------------------------

About JDK and JRE

You must choose whether to install a separate JRE when installing JDK. It is usually installed together. I also recommend that you do this. This helps you better understand the differences between them:

JRE is the Java Runtime Environment and the runtime environment of Java programs. Since it is running, of course it should contain JVM, that is, the familiar virtual machine, and all the class files of Java class libraries are packaged into jar in the lib directory. You can verify it by yourself. Which file is the virtual machine on windows? Anyone who has learned MFC knows what DLL files are. So let's see if there is a JVM. dll in JRE/bin/client? That is, virtual machines.

JDK is a Java development kit and a Java development kit that contains various class libraries and tools. Of course, it also includes another JRE. So why should we include another JRE? In addition, JDK/JRE/bin contains both the client and server folders and a JVM. dll. It indicates that there are two virtual machines. I don't know if you have noticed this yet?

I believe everyone knows that JDK's bin contains the commands required by various Java programs. The most obvious difference with the bin directory of JRE is that javac is available under JDK, which is easy to understand, because JRE is just a runtime environment. It has nothing to do with development. Because of this, JDK's own JRE with the development function will have a client JVM and a server JVM, in the JRE environment, only client JVM is required. DLL is enough.

Do you remember to set the JDK/bin path in the environment variable path? This should be the first step for everyone to learn java. The teacher will tell everyone that javac and Java will not be used if they are not set. The JDK/bin directory contains all the commands. But have you ever wondered whether the Java commands we use are not under the JDK/bin directory but under the JRE/bin directory? Do not believe that you can create an experiment. You can cut the java.exe file in the JDK/bindirectory to another place and run the Java program. What did you find? Everything is OK!

So someone will ask? I have not set the JRE/bin directory to the environment variable?

For example, if Java is provided to most people, they don't need JDK for development, but they only need JRE to run the Java program, so every customer needs to manually set the environment variable. How troublesome is it? When jreinstallation is used, the installation program automatically adds jrejava.exe to the system variables. The verification method is very simple. You can see that the system environment variable path is prefixed with "% SystemRoot % system32; % SystemRoot %, so let's go to Windows/system32 and see what we found? There is a java.exe.

If JDK/bin can be forcibly moved to the front of the System32 variable, of course, the Java in JDK/JRE can also be forced. However, unless necessary, I do not recommend that you do this. Using a separate JRE to run a Java program is also a test in the customer environment.

------------------------------------------------------------------

In short, JDK is an SDK for developers. It provides a Java development environment and a 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.
JDK is the Java Development Kit.
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 in your computer, one in the/JRE and the other in the C:/program files/Java/j2re1.4.1 _ 01 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. After installing JDK, you can choose whether to install the JRE in the C:/program files/Jav a 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 PCs, all have the function of running Java programs. So we can say that as long as your computer has installed JRE, you can run the Jav a application correctly.

1. Why does Sun need JDK to install two identical JRE? This is because JDK has a lot of Java-compiled development tools (such as javac.exe‑jar.exe), and they are all 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, the JDK tool is almost written in Java, so it is also a Java application. Therefore, to use the tool attached to JDK to develop Java programming, you must also attach a set of JRE, therefore, the set of 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 own directory; whether JRE is in its parent directory; and query the registry: [HKEY_LOCAL_MACHINE/software/kerberoft/Java Runtime Environment] The running result of java.exe is closely related to which JRE is executed on your computer.

3. Introduction The bin directory under the jvm jre directory has two directories: server and client. This is where the real JVM. dll is located. JVM. DLL cannot work independently when JVM. after the DLL is started, it will use the explicit method (that is, using loadlibrary () and getprocaddress () in the Win32 API to load the dynamic link library of the auxiliary ), these auxiliary Dynamic Link Libraries (. DLL) must be in the JVM. the parent directory of the dll Directory. Therefore, you only need to set the path to the JVM. dll under the directory where JRE is located.
---------------------------------------------------------------

 

JDK was used to install Java before, and j2re was installed in the company. The relationship between the two is a bit unclear. I searched the internet, as shown below:

In general, JDK is a Java development kit, including JRE. JRE is only the runtime environment of Java. JDK includes JRE of the same version, as well as compilers and other tools.

JDK is the abbreviation of Java Development Kit. It is a development environment for applications, apple, and components published on the Java platform. JDK is the basis of all Java applications, and all Java application procedures are built on it. It is a set of APIS, or Java class. To become a Java programmer, JDK is an essential and basic tool.

JRE is the abbreviation of Java runtime enviroment. It is basically the same concept as a Java virtual machine. Generally, when talking about a specific product, we can say "JRE". When talking about a model in theory, we often use "Java Virtual Machine ". To use Java programs, JRE is an essential environment.

If multiple JDK versions are installed in the machine, as follows:

BEA WebLogic Server 7.0 comes with a set of jdk1.3.1 _ 02
Download a set of the latest jdk1.4.1 _ 02
Jbuilder9 comes with a set of jkd1.4.1 _ 02
Oracle 8.1.7 comes with a set of jre1.1.7
Ration rose comes with a set of jdk1.3
Dreamweaver comes with a set of jdk1.3

6 sets of JRE, each set of JRE is installed in different directories without affecting each other. When java.exe is executed on the console, the operating system looks for jre as follows:

First, check whether there is a JRE in the current directory.
Check whether there is a JRE in the parent directory.
Find JRE In Path
Registry HKEY_LOCAL_MACHINE/software/export oft/Java Runtime Environment/check which JRE the CurrentVersion key value points

The most common method is to find the JRE in the path. Generally, the path will be set temporarily in the batch file before the program runs, place your own JRE at the beginning of the path, so you will certainly run your own JRE without causing version confusion.

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.