Javase Getting Started Learning 4: Building a Java Development environment (II)

Source: Internet
Author: User

In the previous post Javase Getting Started Learning 3: Building a Java Development environment (a) the way we configured the path variable,

Two configuration methods, this configuration is necessary.

PATH environment variable configuration mode 2

Why do we want to use the second configuration form? What is the disadvantage of the first configuration? Suppose I have two JDK installed on my computer, a

One is 1.7, a 1.8, I just configured 1.8, then I need to configure 1.7, need to reconfigure the path environment variable, it is possible to modify the path ring

It is not recommended to use the first if the environment variable is mistakenly deleted from other items.

steps for how to configure the reference configuration for the PATH environment variable:

A) Reopen the system environment variable path to remove the path of the first configuration.

b) Create a new environment variable name: java_home; Add variable value for java_home: JDK installation directory, mine is

are: E:\Java\develop\jdk1.8.0_25


c) Modify the JDK directory in the PATH environment variable to:%java_home%\bin; (% path name% equals reference path name)


d) Restart Dos and use Javac to compile Java source files and Java run bytecode files again.


In this way, when we use other JDK, we can only modify the Java_home variable and not modify the path variable, so we don't delete the other things by mistake.

Cause some other programs to not run.

Let's take a look at a problem with the Java program running, and the result is a good example, which requires another

Configuration of the system variable CLASSPATH.


classpath configuration of environment variables

Why should we configure CLASSPATH environment variables? What is the role of CLASSPATH environment variables?

In future Java program Development, we only need bytecode files, assuming we record the running bytecode file, and the result is the

the same, is unable to run. Therefore, the PATH environment variables configured above can only be used together, if you want to implement a bytecode file to run in any directory,

you need to configure the CLASSPATH environment variable. so its role is: to make the. class in the Classpath directory files can be run in any directory.

Classpath How to configure environment variables

A) Create a new variable name: classpath

b) Variable value: Set to the specified directory containing the class file, using semicolons (;) split between multiple directories. The directory I specified is: E:\Java\JavaSE\Code;


c) Restart DOS and use Java to run the bytecode file.


D) We re-edit a Java source file on the desktop, asking for output: Hello, world, save name or Helloworld.java, continue compiling and

Run.


e) The problem encountered above is that the CLASSPATH environment variable we configured only contains the bytecode file in the directory E:\Java\JavaSE\Code,

Therefore, the workaround is to always add the configured directory to the front.; Configuration, even if the current directory is searched for the. class file, the current directory is searched first, and

After searching according to the order of the directory configuration, it is run after it is found, so the configuration in the Classpath directory is in order.


f) Restart DOS and run the bytecode file on the desktop again.


The value of the configuration classpath we found on the Internet may vary, but the most common of these are the following three Java class library files: Rt.jar is

Java base Class library, Dt.jar is about the runtime environment of the class library, Tools.jar is a tool class library. Let's take a look at these class libraries.

1) Rt.jar default on the root ClassLoader loading path inside the Claspath is superfluous don't believe you can go classpath inside Rt.jar and then use

java-verbose XXXX Way to run a simple class will know the JVM's system root loader the path is not only Rt.jar, most of the jre\lib below

The jar is in this path.

2) Tools.jar is used by the system to compile a class when used to Javac Javac Xxx.java. is actually running Java-

Calsspath=%java_home%\lib\tools.jar Xx.xxx.Main Xxx.javajavac is right the package of the above command, so the Tools.jar does not have to add to

Classpath inside.

3) Dt.jar is a class library about the operating environment, mainly swing's package you'd better add when you want to use swing.

Therefore, the value of the last configured CLASSPATH environment variable is:.; E:\java\javase\code;%java_home%\lib\dt.jar;


the difference between path and classpath

The PATH environment variable is an executable file, such as an. exe file, where the executable file is located in the current path, and if it is not found, go to path.

The path configured in the environment variable to find

The directory where the Java class's running files are located is recorded in the CLASSPATH environment variable.

java-version detecting JDK versions:


the configuration for building a Java development environment is here.

Javase Getting Started Learning 4: Building a Java Development environment (II)

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.