Java environment variable settings and Java View installation path

Source: Internet
Author: User

After installing the JDK on the computer, let's set up the Java environment to use. First right click on my Computer. Open the property. Then select "Environment Variables" in "Advanced", the system variables in the new open interface need to set three properties "Java_home", "path", "Classpath", where the JDK is not installed in the environment. The path attribute is already present. and Java_home and classpath do not exist.

One: Point "new", and then in the variable name write on Java_home, gu name the meaning of the variable is the Java installation path, hehe, and then in the variable value to write the path just installed "C:\jdk1.6". (Note: If the path installed is not disk C or is not in the jdk1.6 folder, it can be modified.) The following text is assumed to be installed inside the C:\jdk1.6. )
Second: In the system variable to find the path, and then click Edit, the meaning of the path variable is that the system can be any path to identify the Java command, the value of the variable is ".; %java_home%\bin ", (where"%java_home% "means to set the value of the java_home just now), you can also write" C:\jdk1.6\bin "directly
Three: Finally click "New", then write classpath on the variable name, the meaning of the variable is the Java load Class (or LIB) path, only the class in Classpath, the Java command can be recognized. Its value is ".; %java_home%\lib\dt.jar;%java_home%\lib\toos.jar (to Add. Indicates the current path) ", same as"%java_home% "

When the above three variables are set, press OK until the Properties window disappears, and it is verified to see if the installation was successful. First open "Start", "Run", enter "cmd", into the DOS system interface. Then hit "Java-version" if the installation was successful. The system displays the Java version jdk "1.6.0".
Ensure that the C-drive file name is jdk1.6, the environment variable is copied directly, enter JAVAC in the DOS interface to see if the command is legitimate, and also enter Java to see if the command is legitimate

Windows:

Code to copy code as follows
Set Java_home: View JDK Installation path
Java-version: View JDK version


Linux:

Code to copy code as follows
Whereis Java
Which Java (Java execution path)
Echo $JAVA _home

Echo $PATH

Two: Here are the environment variables for configuring Linux: (Remember source. bash_profile)
. Modify the/etc/profile file (global All users)


VI This file/etc/profile
At the end of the profile file, add:

Code to copy code as follows
Export JAVA_HOME=/USR/SHARE/JDK1.6.0_20
Export path= $JAVA _home/bin: $PATH
Export classpath=.: $JAVA _home/lib/dt.jar: $JAVA _home/lib/tools.jar

. Modify the. bash_profile file (using these environment variables for a user right)
At the end of the. bash_profile file, add:

Generation (www.111cn.net) code copy Code as follows

Export JAVA_HOME=/USR/SHARE/JDK1.6.0_20
Export path= $JAVA _home/bin: $PATH
Export classpath=.: $JAVA _home/lib/dt.jar: $JAVA _home/lib/tools.jar
The shell terminal executes the following command: (for temporary use)
Export java_home=/usr/share/jdk1.6.0_14
Export path= $JAVA _home/bin: $PATH
Export classpath=.: $JAVA _home/lib/dt.jar: $JAVA _home/lib/tools.jar


So the environment variable is set up, the following to explain the Path,classpth,java_home

The following are the purposes of Java_home,classpath,path:
1, set Java_home:
First, for the convenience of reference, for example, your JDK installed in the C:\Program files\java\jdk1.6.0 directory, then set Java_home as the directory path, then you want to use this path later, just enter%java_home%, Avoid entering a long path string for each reference;
Second, the principle, when you are forced to change the JDK path, you only need to change the value of the java_home variable, otherwise, you will change any of the absolute path references to the JDK directory of the document, if you do not change the whole, a program can not find the JDK, the consequences are imagined----system crashes!
Third-party software will refer to the agreed java_home variable, otherwise, you will not be able to use the software, after a long time in Java will know that if a software does not work properly, you may want to think about this is not the problem.

2, set Classpath:
This is a very interesting, of course, the problem of torture beginners, the purpose of this variable setting is to find the corresponding ". Class" file, you can give an example: you compile a Java program---a.java, you will get a A.class class file, You execute Java A in the current directory, you will get the result (if you have set Classpath to "."). Now, you move the a.class to a different directory (for example: "E:\"), execute Java A, there will be Noclassdeffinderror exception, because the. class file is not found, now you add Classpath to: ".; E:\ "Run Java A again to see what results ~ ~ ~:) ~ ~ ~, everything is OK, java command found the. class file through Classpath!

3, set path:
The reason is simple, you want to use%java_home%\bin\java and so on at any time to execute JAVA commands, of course, you can choose to add%java_home%\bin to path path, so, We can use Java to execute commands under any path. (When you enter your code in the Command Prompt window, the operating system looks for the appropriate application in the current directory and path variable directory, and executes.)


Three. Uninstalling the JDK
• Locate the _uninst subdirectory of the JDK installation directory
• Execute commands at the shell terminal./uninstall.sh You can uninstall the JDK.
From:http://www.111cn.net/jsp/java/53553.htm

Java environment variable settings and Java View installation path

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.