Environment variable settings and descriptions of the roles and objectives of path, classpth, and java_home settings

Source: Internet
Author: User

First, we will introduce how to set environment variables:

(Jdk1.6 is used for installation. Other versions are the same)
After installing JDK on a computer, we can set it to make it usable in the Java environment.

Right-click my computer. Open properties. Then select "environment variables" in "advanced". In the new open interface, you must set three attributes: "java_home", "path", and "classpath ", in this scenario, JDK is not installed. The path attribute already exists. Java_home and classpath do not exist.
Click "new" and write java_home in the variable name. The variable is the installation path of Java: /jdk1.6 ". (Note: If the installation path is not disk C or is not in the jdk1.6 folder, you can modify it accordingly. The following text is assumed to be installed in C:/jdk1.6 .)
Find the path in the system variable and click Edit. the PATH variable indicates that the system can recognize Java commands in any path. The variable value is ".". % java_home %/bin "(" % java_home % "indicates the value of java_home just set), or you can directly write" C:/jdk1.6/bin"
Click "new", and then write classpath on the variable name. The variable indicates the path of the Java loading class (class or Lib). Only the class is in the classpath, java commands can be recognized. The value is ".; % java_home %/lib/DT. jar; % java_home %/lib/toos. jar (to add. indicates the current path) ", which means the same as" % java_home %"
After the preceding three variables are set, press "OK" until the attribute window disappears. verify whether the installation is successful. Open "start"> "run", and press "cmd" to go To the DOS system interface. Then, press "Java-version". If the installation is successful. The system displays Java version JDK "1.6.0 ".
Make sure that the file name on drive C is jdk1.6 and the environment variables can be copied directly. On the DOS interface, enter javac to check whether the command is legal, and enter Java to check whether the command is legal.

In this way, the environment variables are set. The following describes path, classpth, and java_home.

 

Set java_home, classpath, and path as follows:
1. Set java_home:
1. For reference convenience, for example, if your JDK is installed in the C:/program files/Java/jdk1.6.0 directory, set java_home to the directory path, to use this path in the future, you only need to enter % java_home % to avoid entering a long path string for each reference;
Ii. Normalization principle: when your JDK path is forced to change, you only need to change the variable value of java_home. Otherwise, you need to change any document that uses the absolute path to reference the JDK directory, if you fail to complete the changes and a program cannot find the JDK, the consequence is that the system crashes!
3. The third-party software will reference the agreed java_home variable. Otherwise, you will not be able to use the software normally. After using Java for a long time, you will know that if a software cannot be used normally, think about the problem.

2. Set classpath:
This is a very interesting question. Of course, it is also a question that affects beginners. The purpose of this variable setting is to allow the program to find the corresponding ". for example, compile a Java program ---. java,. class class file. If you execute Java A in the current directory, the corresponding result will be obtained (provided that you have set classpath ". "). now. when the class is moved to another directory (for example, "E:/") and Java A is executed, there will be a noclassdeffinderror exception because it cannot be found. class file, now you add classpath :".; e:/"run Java A again to see what the result will be ~~ :)~~~, Everything is normal. The Java Command finds the. Class file through classpath!

3. Set path:
The principle is very simple. Do you want to use % java_home %/bin/Java to execute Java commands at any time? Of course not, so, you can add % java_home %/bin to the path. In this way, we can use Java to execute commands in any path. (When you enter your code in the Command Prompt window, the operating system will find the corresponding application in the current directory and PATH variable directory and execute it .)

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.