Java environment settings on JDK, JRE, and Ubuntu

Source: Internet
Author: User

I. Differences between JRE and JDK [reprinted]

JDK is a Java Development Kit. In short, it is a development tool for developers. These software development packages include function libraries and compiled programs. It provides a Java development environment and runtime environment.

JRE is a Java Runtime Environment, 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 on the computer, one at \ JRE and the other at c: \ Program Files \ Java \ jre1.5.0, the later part is less server-side Java virtual machine than the previous one, but simply copy the previous server-side Java virtual machine.

1. Why does Sun need JDK to install two identical JRE?

Many Java development tools such as javac.exe \ jar.exe are stored in \ Lib \ tools. jar. 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. In this case, you enter javac.exe and Java-CP c: \ JDK \ Lib \ tools. jar COM/Sun/tools/javac/main is the same and will get the same result. Therefore, we can prove that javac.exe is only a package to prevent developers from inputting too long. The programs in the \ lib directory are very small, not greater than 29 K. From this point, we can draw a conclusion that all the tools in JDK are written in Java and are also Java applications, therefore, to use these tools, you must add a JRE.

 
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 \ javasoft \ Java Runtime Environment] The running result of java.exe has a great relationship with which JRE is executed on your computer.

Add :( small summary)

JVM -- Java virtual machinejvm is the most common 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 environmentjre 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, while JVM and
Lib is 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 kitjdk is a Java Development Kit. Basically, everyone who learns Java will first install a JDK on the machine. Which part does it contain? Let's take a look at the JDK installation directory. The directory contains six folders, one SRC Class Library source code package, and several other declaration files. Specifically, the following four folders actually work when running Java: Bin, include, Lib,
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, while JRE can only run 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.

2. Install JRE in Ubuntu

The installation is based on the Root permission.

1. First download a Linux zip package from the Oracle Java official network. I downloaded jre-6u17-linux-i586.zip.

2. Place this package in the directory you want to install, I install it under/usr/Java, and then unzip, unzip the command is unzip jre-6u17-linux-i586.zip, unzip and get the jre-6u17-linux-i586.bin

3. After getting the bin package, set the File Permission chmod A + x jre-6u17-linux-i586.bin. Next, you will be prompted for the binary license protocol, and type the Yes key.

4. Install the Java environment after you see done.

5. Environment Variable Configuration

Entering Java directly in shell does not work. You must configure the environment variable first. Although the Export command can be used in shell, this setting only works for the current shell. Restarting or switching to another shell will no longer work, so I set it directly in/etc/profile. Enable/etc/profile with vim under root, and add

Export java_home =/usr/Java/jdk1.6.0.17

Export classpath =.: $ java_home/lib/DT. jar: $ java_home/lib/tools. jar (because I only installed a runtime environment without these Development kits, I didn't set it)

Export Path = $ path: $ java_home/bin

You can also set these environment variables in/etc/environment.

6. Verification: re-open a terminal, enter Java-version, and check the result.

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.