JDK and JRE and their use in eclipse

Source: Internet
Author: User

Reprinted from: http://blog.csdn.net/gx1058742912/article/details/51033942

the difference between JDK and JRE

JDK (Java Development Kit): Java development tools, including a series of Java commands, such as Javac (Java compiler), and the JDK contains the JRE, because the JDK is actually for Java developers, open After the completion of the commissioning of the run, etc., which requires the JRE;

JRE (Java Runtime Environment): Java Runtime Environment, Java files are javac compiled after the formation of bytecode files, this file computer is not understood and processed, need to have a JVM (Java virtual Machine) is processed and the language is passed on to the computer (which is why Java is platform agnostic). The JVM is present in the JRE. As you can see, the JRE is actually a user for Java programs;

So, when you need to develop a Java program, you need a JDK, but if you need to run a Java program, you will need the JRE. The confusing thing is that when you download and install the JDK, you'll find that the JRE folder exists both inside and outside the JDK folder (proving that the JDK contains the JRE), so let's say why:

Internal JRE: When you develop a Java program, you need to use some commands such as Javac to invoke the JRE inside the JDK (Java development tool);

External JRE: When you only need to run a Java program rather than develop it, the external JRE is called;

So why split two? The public one is not OK, but also save resources. Actually divided into two jre, more is to improve performance and efficiency, open two JRE folder, contrast will find:

In the external JRE, in its client folder, There is a jvm.dll; inside the JRE, there is a server folder, which also has a Jvm.dll file, mainly two VM differences, so that the internal and external JRE has different division of labor, and can be the best in their respective division of labor (improve their efficiency and performance).

Attach a copy of the Oracle website:


(http://docs.oracle.com/javase/7/docs/)

From this picture, you can get: JVM? JRE? JDK

Speaking of which, by the way, the Windows environment variables in the path and classpath, after all, good memory than rotten pen!

After installing the JDK, the next step is to configure the environment variables, how to configure not much to say, online a lot, simple to say why to divide the two to configure:

Path variable: The paths corresponding to the values in the following are some Java command programs, such as Javac;

Classpath variable: The path corresponding to the value below is some Java-provided classes (jar packages) that the program needs to use.

Sometimes the JAVA_HOME environment variable is used, which points to the JDK's installation directory, Eclipse/tomcat, and so on, to find and use the installed JDK. Once configured, Java programs can be executed in any directory with Java commands. So why can the system use the commands provided by the JDK in any directory?

In fact, the environment variable is able to make the system faster and easier to find what is needed, interested can look at the Windows system variables in the path variable in the existing values, such as C:\Windows\system32;, open by this path, you will find that there are many executable files, For example, Cmd.exe, this is why we can have the command line after we enter CMD in the Run window. In this case, you can also try to use environment variables to start other programs!

jdk and JRE in eclipse:

In fact, the starting point for writing this article is that when using Maven in Eclipse, the various JRE and JDK were confused and decided to figure it out. Let's start with a brief introduction:

Eclipse: is an integrated development of the IDE, you can develop, compile, debug, run code and so on;

Jdk:java development tool for compiling. java files into byte-code files;

Jre:java runtime Environment, execute compiled bytecode file;

Maven: a project management tool;

The Java compiler is actually embedded in eclipse, and its compiler is equivalent to the javac in the JDK, so eclipse just needs the JRE to compile the Java file (in Eclipse, when you save a Java class, it automatically compiles the Java class, Equivalent to using the JAVAC command in the command line). But if you used a tool like Maven in Eclipse, you might not be able to compile it. Because Maven uses JAVAC to compile the project by default, that is, it requires a JDK, and if you have a MAVEN project in eclipse that specifies only the JRE, there will be an inability to compile. It's like launching Tomcat requires only the JRE because the source code compiler has been included in Tomcat and does not require the javac in the JDK to compile.

There are a few places in eclipse that will use JDK and JRE, and here are a few, and that's where I mess up:

A. window->preferences->java->installed JREs


Here installed JREs can be understood as "global constants", set up here, and then the new project will default to the JRE or JDK selected here, but if Maven is used in the project, the previous MAVEN default is the JDK Javac to compile, So if you use the JRE here, then maven install error, need to choose the JDK. Change the direct Add->standard VM, click Directory, select the appropriate JDK or JRE path to determine.

B. Choosing a different JRE for different projects

Right-click the project name->build path->configure build path, select the Libraries tab, select JRE:


Click Edit:


You can select different tabs according to different needs and follow the prompts to complete the operation. Note that when you select the Second tab "Alternate JRE", Eclipse jumps to the installed JRE for you to choose from, so you need to configure it in advance in the installed JRE.

C. Window->preferences->java->compiler

There will also be a JDK selection, which is the version of the JDK at compile time, one thing to note:

The JDK version at compile time cannot be higher than the JDK in the project build path, which is the runtime JDK, because some features in the high version are not available in the lower version. For example, the project uses generics, compile-time is jdk1.5 but run-time is jdk1.4, although compile without error, but run-time error, because jdk1.4 does not support generics, in turn, compile time for jdk1.4 and run as jdk1.5, although compile times wrong, but can run correctly.

JDK and JRE and their use in eclipse

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.