Many people on the Internet can find the JDK environment variable configuration, but basically did not explain the role of these environmental variables, today I would like to say:
Typically, after installing the JDK, you need to configure two environment variables:PATH and CLASSPATH(because the Windows platform has no requirement for system variables, capitalization is possible, but only uppercase in a Linux system).
Maybe some people say there is a java_home, in fact, this variable is set to play the role of the relay, Java_home point to our JDK installation directory, the purpose of customizing this variable is probably to let us more convenient use of JDK installation directory bar (personal understanding), so Java_ Home is optional.
to talk about the two system variables of path and classpath, you have to look at several folders below the root of the JDK:
One of the main is bin, JRE, Lib three folders,
bin: The path to store a variety of JDK tool commands, commonly used in Javac, Java, etc.
JRE: This path installs the JRE environment that is required to run Java programs;
Lib: This path holds the actual execution code program for the JDK Tool command, and the Dt.jar and Tools.jar in the folder are class files (. Class) of the tool commands.
Let's talk about the two system variables of path and classpath:
It takes two steps to compile and run the Java program first:
1. Compile the. Java source file into a. class byte code;
2, to interpret the implementation of the platform-independent bytecode program;
These two steps are used in both the Javac and Java commands respectively.
When we run these two commands, how does the computer find these two commands? Which is how to find the path of the two commands. So we're going to set the path for this tool command so that the computer can find them on its own. Windows operating systems look for commands based on the system variable path, so we add the path of the tool command (Bin directory) to the path, and the computer can find it (add D:\Java\jdk1.7.0_01\bin to the PATH environment variable):
The different paths in the environment variable are separated by semicolons , separated by a colon under Linux.
In this way, when you run Java, Javac, and other tool commands in a DOS environment, the computer can automatically find the path to the command and execute it.
The computer then finds the command according to the path inside, but the path (that is, the bin directory) is a reference to the tool command (shortcut bar), the specific tool command program is saved in the Lib directory, so this time the computer just find the tool command not yet, Also find its execution body, which is a few Java compiled. class files (Dt.jar and Tools.jar in the Lib directory), so we're going to set up an environment variable to place the paths of these two files (that is, the package Dt.jar and Tools.jar) Environment variables so that the computer can find execution.
And for class files, Java set up an environment variable classpath specifically to point to class files, the computer according to the environment variable below the path, you can find the corresponding class files and executed. So after the JDK is installed, the D:\java\jdk1.7.0_01\lib\dt.jar;d:\java\jdk1.7.0_01\lib\tools.jar two paths are added to the classpath.
And we usually set the classpath path before there is a point, that is, the complete classpath is .;D: \ Java\jdk1.7.0_01\lib\dt.jar;d:\java\jdk1.7.0_01\lib\tools.jar
What is this point for? (Assuming that you have a compiled Java file hello.class)
We execute this file Java Hello this time the JRE is where to search for this file. Some people may say that the current path search AH. This is right to search under the current path, but JDK1.4 and previous versions did not design this feature, which means that even if the current path contains the Hello.class file, the system will not find the Hello class when executing the java Hello command.
So in JDK1.4 and prior versions, you need to add a point (.) to the CLASSPATH environment variable to tell the JRE that it needs to search the Java class under the current path. So Classpath also has the above path (.;D: \ Java\jdk1.7.0_01\lib\dt.jar;d:\java\jdk1.7.0_01\lib\tools.jar).
In short, classpath this environment variable is used to find the class. By adding the corresponding classpath, the system can be retrieved and executed automatically.
In JDK1.5 and later releases, you can not set CLASSPATH this environment variable , because the JRE is smarter than before, it automatically searches for class files under the current path, and when using Java's compile and run tools, The system can also automatically load Java classes in Dt.jar and Tools.jar files, so you no longer need to set up CLASSPATH environment variables.
But when we use JDK1.5 and later releases, if you set the CLASSPATH environment variable, the JRE will search the Java class according to the path specified by the CLASSPATH environment variable instead of automatically looking for the Java class, so set up your own classpath. , be sure to set the correct, or not run.
The above is a personal summary, if there are objections do not spray.