......................................................................................................................... ............................
cl asspath? What is the role of it? It is an environment variable of the Javac compiler. Its role is related to import, the package keyword. When you write down Improt java.util.*, when the compiler faces the import keyword, you know you want to introduce java.util the class in the package, but how does the compiler know where you put the package? So you first have to tell the compiler where the package is located, and how do you tell it? is to set classpath:) If java.util this package in the C:\jdk\ directory, you have to set c:\jdk\ this path to Classpath! When the compiler faces the import java.util.* this statement, it first looks for the directory specified by Classpath and checks to see if the subdirectory java\util exists, and then finds the compiled file (. class file) that matches the name. If you do not find it will be an error! The classpath is a bit like the settings of the include path in the C\c++ compiler oh, isn't it? When the C\c++ compiler encounters a statement such as include <iostream>, how does it work? Oh, the truth is almost the same! Search the Include path to view the file! When you develop a package yourself and then want to use the class in the package, naturally, you also have to set the directory where the package resides in Classpath! The classpath setting is a tricky thing for beginners in Java. So Sun made JAVA2 's jdk a little bit smarter. You will find that after you install, you can still compile the basic Java program and execute it even if you have not set classpath at all. ......................................................................................................................... ............................ 1. Path environment variable. The function is to specify the command search path, execute the command below the command line, such as Javac compiling the Java program, it will look in the path specified by the paths variable to see if the corresponding 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 of course is to find them, the JVM is through Classpath to find the class of the. class file. 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. Javac-c Path (You can specify a class file to store the directory)
JAVA-CP Path (You can specify the class directory to execute)
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. On the Windows desktop, right-click "My Computer", "Properties", "Advanced", "Environment variables", in "system variables" we can see the values of the system's various environment variables. Double-click a variable name to modify the value of the variable, using ";" between the variable values. Separated. We can also "create new" variables that were not previously available. There are 3 environment variables associated with the JDK, "java_home", "path", "Classpath". The "path" variable already exists in my system, can add the new value directly (other variable values do not move, prevent other programs to run the exception), the other two variables need to be new.
"Java_home", set the JDK installation path, such as "e:\java\jdk1.5", hereinafter referred to as "%java_home%".
"Path", set the path of each program in the JDK, "%java_home%\bin;%java_home%\jre\bin;"
"Classpath", set the path of each class in Java, ".; %java_home%\lib;%java_home%\lib\tools.jar ". The previous "." No less, it represents the working path we have built for our Java class, and the other is the standard class library path that comes with the JDK.
After setting the environment variable, press OK to exit. Press "Win" + "R" key into the "Run" window, run "cmd" into the DOS window, enter "Javac" after entering, if there is help information showing Java, the environment variable setting is successful. Classpath= ".; %java_home%\lib;%java_home%\lib\tools.jar " Java_home = "C:\Program files\java\jdk1.5.0" Path = "%java_home%\bin;%java_home%\jre\bin" |