First, let's talk about the procedure, then the principle
1. Right-click My Computer---Properties-----advanced system settings (Advanced)---environment variables.
2. Select "New System Variable"--pop up the "New System Variable" dialog box, enter "java_home" in the "Variable name" text box, enter the installation path of the JDK in the "Variable Value" text box, and click the "OK" button.
3. View the path variable in the system Variables options area, and if it does not exist, create a new variable path, otherwise select the variable, click the Edit button, and add "%java_home%\bin;%java_home%\jre\bin;" At the beginning of the Variable Value text box. or direct "%java_home%\bin;", click the OK button.
4. View the CLASSPATH variable in the system Variables options area, and if it does not exist, create a new variable classpath, otherwise select the variable, click the Edit button, and add "at the beginning of the Variable Value text box."; %java_home%\lib\dt.jar;%java_home%\lib\tools.jar; ".
5. Now the test environment variable is configured successfully or not. Enter "JAVAC" in the DOS command line window and the output Help information is configured correctly.
Precautions
Remember not to miss out on the last ";" Symbol.
Now let's talk about the principle
Java_home: The value of this environment variable is the directory where Java is located, some Java version of the software and some Java tools need to use this variable, set PATH and CLASSPATH, you can also use this variable to facilitate setup.
path: Specify a list of paths, that is used to search for executable files. . When executing an executable file, if the file cannot be found under the current path, look for each path in path until it is found. Or if you find the path in the paths can not be found, the error. Java's compilation commands (Javac), execution commands (Java), and some tool commands (Javadoc, JDB, etc.) are in the Bin directory under its installation path. So we should add that path to the path variable.
CLASSPATH: Also specify a list of paths, is the class used to search for Java compilation or run-time . In the CLASSPATH list, you can include a. jar file in addition to the path. Java finds the. jar file as a directory to find the class. In general, we need to include Jre/lib/rt.jar (Linux:jre/lib/rt.jar) under the JDK installation path in CLASSPATH ( a "current directory (.)" is included in the CLASSPATH. Once the directory is included, you can go to any directory to execute a Java program that needs to use a class in that directory, even if the path is not included in the CLASSPATH. The reason is simple: Although the path is not explicitly included in the CLASSPATH, the "." In CLASSPATH represents the path at this point .
Both path and CLASSPATH specify a list of paths, separated by delimiters between the items in the list (that is, the individual paths). Under Windows, the delimiter is a semicolon (;), and under Linux, the delimiter is a colon (:).
More detailed reference: How to set Java environment variables
Java Configuration Environment variables