Configure the JDK environment variables under Windows XP:
1. Install the JDK, the installation process can customize the installation directory and other information, such as we choose the installation directory for D:\java\jdk1.5.0_08;
2. After the installation is complete, right-click on "My Computer" and click "Properties";
3. Select the "Advanced" tab and click on "Environment variables";
4. In "System Variables", set 3 properties, Java_home,path,classpath (case does not matter), if already exist then click "Edit", do not exist then click "New";
5.java_home: Indicates the JDK installation path, which is the path D:\java\jdk1.5.0_08 selected at the time of installation, including folders such as LIB,BIN,JRE (this variable is best set, because Tomcat is run later, Eclipse and so on need to rely on this variable)
Path: Allows the system to identify JAVA commands under any path, set to:%java_home%\bin;%java_home%\jre\bin
CLASSPATH: For Java load class or lib path, only the class in CLASSPATH, Java command can be recognized, set to:.; %java_home%\lib\dt.jar;%java_home% \lib\tools.jar (to Add. Indicates the current path)
%java_home% is referring to the previously specified java_home;
6. "Start" → "Run", type "cmd";
7. Type the command "Java-version", "Java", "Javac" several commands, appear screen, indicating that the environment variable configuration is successful;
8. OK, finish the call. Let's start with your first Java program.
Here are the meanings of several JAVA environment variables and how to configure Linux: Typically, we need to set up three environment variables: java_home, PATH, and CLASSPATH.
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: Specifies a list of paths that are 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 specifies a list of paths that are used to search for Java compilations or classes that need to be run. 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.
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 (:).
Here's a description of how the three environment variables are set under Windows and Linux, but before that we need to make a hypothesis. Assuming that the JDK installation path under Windows is C:\jdk\, the installation path under Linux is/usr/local/jdk/. Then, the installed JDK will include at least the following: C:\jdk (/USR/LOCAL/JDK)
|--bin
|--Demo
|--include
|--JRE
| |--bin
| '--lib<br> '--lib*****
Set environment variables using the SET command under Windows settings </p>windows, in order for each startup computer to set these environment variables, it should be set in the Autoexec.bat file under the system packing directory, such as: Set Java_home= C:\jdk<br>set Path=%java_home%\bin; C:\Windows; C:\windows\command<br>set Classpath=%java_home%\jre\lib\rt.jar;. Some versions of Windows cannot replace the contents of an environment variable with the% variable name%, so they have to write C:\jdk instead of%java_home%.
In addition, C:\Windows and C:\Windows\Command are automatically added to the path, so you can remove them from the settings. If path is already set in Autoexec.bat, it is only necessary to add%java_home%\bin to the same statement that set path.
CLASSPATH can also be set or added to other paths as needed, such as you want to write some of the classes in C:\java, you can add C:\java to CLASSPATH, set Classpath=%java_home%\jre\lib \rt.jar; C:\java, ....
Notice that 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, as:</p> assumes that there are classes Hellojava.class in the C:\java directory that can be run, then < /p>c:\> Set Classpath=c:\jdk\jre\lib\rt.jar;. Set the CLASSPATH environment variable, and note that there is finally a "."
C:\> CD Java//go to C:\java directory
c:\java>; Java Hellojava//Run Hellojava
Hello, Java. Run results
c:\java>; _**** set under Linux
Under Linux, use the variable name = variable value to set the variable and export it as an environment variable using the Export command. In order for each login to automatically set these variables, you need to set them in ~/.bash_pro file or ~./BASHRC, such as </p>export java_home=/usr/local/jdk<br> Export path= $JAVA _home/bin: $PATH <br>export classpath= $JAVA _home/jre/lib/rt.jar:. $JAVA _home When setting PATH is the substitution variable The value of the Java_home to the location where the $JAVA _home. As the above sentence is actually export path=/usr/local/jdk/bin: $PATH. This is the same $PATH, but the path here refers to the value of the path variable that was previously set, not the value of the path variable this time.
Notice that 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, for example
Assuming there is a class Hellojava.class in the/home/fancy/java directory that can be run, then
[Email protected] fancy]$ export Classpath=/usr/local/jdk/jre/lib/rt.jar:. Set the CLASSPATH, and note the last "." [[Email protected] fancy]$ CD ~/java//Go to/home/fancy/java<br>[[email protected] java]$ pwd//show current directory
/home/fancy/java//current directory is/home/fancy/java<br>[[email protected] java]$ java Hellojava//Run Hellojava
Hello, Java//Run result
[[Email protected] java]$ _ Analysis
Instance analysis is just different from the operating system, slightly differently.
Two examples refer to a "running class", which refers to a class that contains the public static void main (string[] args) method, which is detailed in the next chapter, Hellojava. The CLASSPATH in the example do not contain the directory in which Hellojava.class resides (C:\java,/home/fancy/java), but both contain the current directory (.). So go to the directory containing Hellojava.class and execute Java hellojava, looking in Java for CLASSPATH ". (current directory, C:\java,/home/fancy/java) "When Hellojava.class was found, the operation was successful.
2, Classpath, Path, the role of Java_home