Build a Java environment

Source: Internet
Author: User

From http://blog.csdn.net/ghj1976/article/details/5543428

 

First, we should have a certain understanding of JDK, JRE, and JVM. The following figure can clearly express their relationship:

Relationship between JDK, JRE, and JVM

A more complex diagram: This is a j2se 1.5 functional chart. On the left side of the diagram, we can clearly see which JVM categories are and which JRE categories are, which are the categories of JDK.

Java Program Execution logic

The figure below demonstrates how to create a personalized Java starter, which is helpful for us to understand the Java execution logic. This is an example of creating a personalized Java starter in the window environment.

This figure comes from: creating a personalized Java starter

The most common initiator is the starter of sun in the/bincatalog of Java Runtime Environment. For Windows platform, these are java.exeand javaw.exe. The former opens two windows during runtime: one is the console window that receives the system. Out/err and the initiator output, the other is the Java program itself, and the javaw does not open the console window during runtime.

On the j2se/EE platform, virtual machines are implemented in the form of dynamic libraries and are also stored in the/bin directory. The dynamic library name is Java. dll in windows and Java. So in UNIX. The so-called "Mount Virtual Machine" refers to loading this dynamic library.

The logic for finding this dynamic library is to search in sequence 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 to (this is of course exclusive to Windows .)

Unlike. net,. NET introduces the global application cache (GAC). One machine, one version of. NET Framework, has only one set, and does not need to be considered in GAC.

 

Search for jre class library

The basic library that comes with JRE is the JRE/lib/RT. jar file, which includes all the class libraries of the Java 2 platform Standard Edition. The version is the same as that of JRE.

In JRE, classloader is responsible for finding and loading the class libraries referenced by the program. The base class library classloader will go to Rt. jar is automatically loaded. Other class libraries and classloader are searched in the path specified by the Environment Variable classpath. The class libraries placed before classpath are first searched.

We recommend that you set the path and classpath environment variables before starting the Java program. OS uses path to find JRE and determine the location of RT. jar in the base class library. The classloader of JRE uses classpath to find other class libraries.

 

 

JDK Installation

Go to the http://java.sun.com/javase/downloads/index.jsp to download the latest JDK. Download and install.
After windows is installed, you need to set three environment variables.

Java_home

Specifies the JDK installation path, which is the path C:/program files/Java/jdk1.6.0 _ 19 during installation. This path contains Lib, bin, JRE, and other folders (it is best to set this variable, this variable is required for running tomcat, eclipse, and ant in the future)

Path

Path allows the system to recognize Java commands in any path. It is set:

% Java_home %/bin; % java_home %/JRE/bin

Classpath

Classpath is the class or lib path of the Java load class. Only the class in classpath can be identified by the Java command and set:

.; % Java_home %/LIB; % java_home %/lib/tools. Jar

(Add. to indicate the current path)
% Java_home % refers to the previously specified java_home.

In Linux, configure the following settings (taking Ubuntu as an example ):

after the download, we start to install the SDK. (Assume that the downloaded file is jdk1.6.bin.)
open the folder in the command line and press chmod U + X. /jdk1.6.bin (Change executable permissions: U indicates the owner of the file, + indicates adding permissions, and X indicates executable)
then. /jdk1.6.bin
when you see the protocol, press down or enter (the Protocol is quite long).
at last, you can see
Do you agree to the above license terms? [Yes or No]
whether to accept the request. Of course, Press Y to pull it ~
then we can see that the default file name after decompression is jdk1.6.0
and then press
sudo CP-r jdk1.6.0/usr/(CP-R: recursive continuous replication is used for directory replication .)
copy it to the USR directory
OK, by now, only the environment is configured.
export java_home =/usr/jdk1.6.0
export classpath = $ classpath: $ java_home/lib: $ java_home/JRE/lib
export Path = $ java_home/bin: $ java_home/JRE/bin: $ path: $ homr/bin
call VI ~ /. Bashrc (VI command see: http://yanxi.bokewu.com/blog93673.htm)
enter the user environment variable configuration interface, add the above three lines to the end, ESC ,: WQ
Save and exit
so that JDK is configured ~

See:
Http://forum.ubuntu.org.cn/viewtopic.php? F = 44 & t = 174375
Http://forum.ubuntu.org.cn/viewtopic.php? T = 39742
Http://www.360doc.com/content/08/1012/12/61497_1749889.shtml
Http://forum.ubuntu.org.cn/viewforum.php? F = 70

 

Then we can write a super simple Java program.

In sequence: javac test. Java

Java Test

To test whether it can run normally.

 

You can also set the JDK version in eclipse,

In our project, right-click Properties> Java compiler and set the level of compiler compliance to the version we need.

Note that eclipse does not have its own JDK, and it only needs JRE to run (javac is not required), because it comes with a compiler (compile package exists in the plugin directory ).

At runtime, eclipse starts startup. Jar by using the Java command (Windows or Linux) added to the environment during JRE installation. However, if only JRE is usedSource codeEclipse cannot generate type comments in the library based on the source code.

 

How can I view the version of the current Java Runtime Environment?

Use Java-fullversion under the command line to view the current version.

 

 

References:

Differences and connections between JDK, JRE, and JVM
Http://www.blogjava.net/jzone/articles/271115.html

Summary of the relationship between SDK, JDK, JRE, and JVM
Http://blog.csdn.net/achun2050/archive/2007/05/08/1600370.aspx

Summary of the CLR and JRE Operating Mechanisms
Http://developer.51cto.com/art/200910/158035.htm

How to Make java run in a specified version of JRE.
Http://hi.baidu.com/blueleopard/blog/item/cd46d4f9e5b91e5c252df286.html

How to run a Java program
Http://wenwen.soso.com/z/q131473345.htm

Java program running mechanism and running process
Http://www.cnblogs.com/xiaoQcn/archive/2010/01/26/1656394.html

About JDK
Http://blog.csdn.net/yqj2065/archive/2005/02/28/305593.aspx

Create a personalized Java starter
Http://www.pconline.com.cn/pcedu/empolder/gj/java/0404/346719.html

Install and configure Java program JRE in Linux
Http://tech.ddvip.com/2007-08/118717162731923.html

Relationship between JDK, JRE, and JVM
Http://www.cjsdn.net/post/view? Bid = 1 & id = 9965 & sty = 1 & TPG = 1 & age = 0

Download and install JDK and configure its environment variables
Http://www.svn8.com/java/pz/20080531/729.html

The eclipse compiler is really different from Sun's javac.
Http://www.javaeye.com/topic/318996

How to configure JDK in eclipse
Http://tech.ddvip.com/2008-12/122855371598107.html

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.