Java Environment variables

Source: Internet
Author: User

Why set the Java environment variable (detailed)

1. Path environment variable. The function is to specify the command search path, and when executing the command under the shell, it looks in the path specified by the path variable to see if the appropriate command program can be found. We need to add the bin directory in the JDK installation directory to the existing path variable, and the bin directory contains the frequently used executables such as Javac/java/javadoc wait, and after setting the path variable, you can execute the Javac/java tool in any directory.

2. CLASSPATH environment variables. The role is to specify the class search path, to use the already written classes, the premise is to be able to find them, the JVM is through the classpth to find the class. We need to set the Dt.jar and Tools.jar in the Lib subdirectory of the JDK installation directory to classpath, of course, the current directory "." must also be added to the variable.

3. Java_home environment variables. It points to the JDK's installation directory, and software such as Eclipse/netbeans/tomcat finds and uses the installed JDK by searching for java_home variables.

How to install the configuration Java environment variable JDK:Install the JDK arbitrarily select the directory just the default installation directory \java directory;

Environment variables:

1. After the installation is complete, right click on "My Computer", click "Properties", select "Advanced System Settings";

2. Select the "Advanced" tab and click on "Environment variables";

The screen will then appear as shown:

Set 3 properties in "System variable", Java_home,path,classpath (case does not matter), if already exist then click "Edit", not exist then click "New".

The variable setting parameters are as follows:

    • Variable name: java_home
    • Variable Value: C:\Program Files (x86) \java\jdk1.8.0_91//To be configured according to the actual installation path of your JDK
    • Variable name: CLASSPATH
    • Variable value:.;         %java_home%\lib\dt.jar;%java_home%\lib\tools.jar; Remember, there's a "." in front.
    • Variable name: Path
    • Variable value:%java_home%\bin;%java_home%\jre\bin;
Java_home settings

Path settings

CLASSPATH settings

This is the Java environment configuration, after the configuration is complete, you can start Eclipse to write code, it will automatically complete the configuration of the Java environment. (PS: If you use more than 1.5 versions of the JDK, do not set the CLASSPATH environment variable, you can also compile and run the Java program properly)

Test whether the JDK was installed successfully

1, "Start", "Run", type "cmd";

2, type the command: Java-version, Java, javac several commands, the following information appears, indicating that the environment variable configuration is successful;

Verify the first Java program under the console:

public class Test {public    static void Main (string[] args) {        System.out.println ("Hello Java");}    }

Write in Notepad, click "Save", and deposit the C packing directory, enter Javac Test.java and Java Test command, you can run the program (print out the result "Hello Java"). Note: These two commands are under the D:\java\jdk1.8.0_20\bin directory.

Program parsing:

First write the Java source Code program, extension. java;

In command-line mode, enter the command: Javac the source file name. Java, compile the source code, generate a class bytecode file;

After compiling, if there is no error message, enter the command: Java HelloWorld, the class bytecode file interpretation run, do not need to add the. class extension. See:

Note: If you enter the Javac test.java command in CMD, the display of ' Javac ' is not an internal or external command because the JDK development environment or environment variable configuration is not installed in the wrong place.

Java Environment variables

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.