What is classpath? What is its role?
It is an environment variable of the javac compiler. Its role is related to the import and package keywords. When you write improt Java. util. * When the compiler faces the import keyword, it will know that you want to introduce Java. util is a class in the package. But how does the compiler know where you put the package? So you must first tell the compiler where the package is located. How can you tell it? Set classpath. If the java. util package is in the C:/JDK/directory, you must set the C:/JDK/path to classpath! When the compiler faces the import Java. util. * In this statement, it first looks for the directory specified by classpath, checks whether the subdirectory Java/util exists, and then finds the compiled file (. class file ). If not found, an error is returned! Classpath is a bit like the include path settings in the C/C ++ compiler, isn't it? How does a C/C ++ compiler operate a statement such as include? Oh, the truth is almost the same! Search include path and View File! When you develop a package, you want to use the classes in the package. Naturally, you have to set the directory of the package to classpath! Classpath settings are tricky for beginners of Java. So Sun makes JDK of Java2 smarter. After installation, you will find that, even if classpath is not set at all, you can still compile and execute basic Java programs.
........................................ ........................................ ........................................ .............................
1. PATH environment variable. The role isSpecify command search path, Execute the command below the command line, such as javac compiling JavaProgramIt will go to the path specified by the PATH variable to check whether the corresponding command program can be found. We need to add the bin directory under the JDK installation directory to the existing PATH variable. The bin directory contains frequently used executable files such as javac/Java/javadoc waiting, after setting the PATH variable, You can execute tools such as javac and Java in any directory. The path value we set here is:
% SystemRoot %/system32; % SystemRoot %/system32/WBEM; % SystemRoot %/system32/windowspowershell/V1.0/; C: /program files/common files/thunder Network/Kankan/codecs; C:/program files/Microsoft SQL Server/90/tools/binn/; C: /program files/common files/ttkn/bin; C:/program files/common files/teleca shared; C:/program files/Java/jdk1.6.0 _ 21/bin
The above only contains the red part.; C:/program files/Java/jdk1.6.0 _ 21/binIs the Java PATH variable. Note that the variables must be separated.
2. classpath environment variable. The role isSpecify the category search pathTo use the classes that have already been compiled, the premise is that you can find them, and JVM searches for classes through classpath. We need to set DT. jar and tools. jar in the Lib subdirectory under the JDK installation directory to classpath. Of course, the current directory "." must also be added to this variable. Here classpath is:
.; C:/program files/Java/jdk1.6.0 _ 21/lib/dt. jar; C:/program files/Java/jdk1.6.0 _ 21/lib/tools. Jar
3. java_home environment variable. ItPoint to the JDK installation directoryEclipse, netbeans, tomcat, and other software find and use the installed JDK by searching the java_home variable. Java_home:
C:/program files/Java/jdk1.6.0 _ 21
........................................ ........................................ ........................................ .............................
Java environment variable configuration steps:
On the Windows desktop, right-click "my computer"-> "properties"-> "advanced"-> "environment variable ", in "system variables", we can see the values of various system environment variables. You can double-click a variable name to modify the variable value. The variable values are separated by commas. We can also "CREATE" variables that are not previously available. JDK-related environment variables include "java_home", "path", and "classpath ". In my system, the "path" variable already exists. You can directly add a new value (other variable values should not be dynamic to prevent other program running exceptions). The other two variables need to be created.
Classpath =.; % java_home %/lib/dt. jar; % java_home %/lib/tools. Jar
Java_home = C:/program files/Java/jdk1.5.0
Path = % java_home %/bin; % java_home %/JRE/bin
From the above, we can see that both path and classpath use java_home, or they can use absolute paths.