The setting and function of java_home path classpath in the Java environment variable.
Today, I set the Java environment variable again. I suddenly found that every setting was completed step by step. I didn't know why I needed to set it. So I searched the internet and found the article, I think it's good. I will leave it here.
Only for record learning. From: http://bbs.tech.163.com/bbs/tech_0ik1/147645925.html
After installing JDK on a computer, we can set it to make it usable in the Java environment. Right-click my computer. Open properties. Then select "environment variables" in "advanced". In the new open interface, you must set three attributes: "java_home", "path", and "classpath ", in this scenario, JDK is not installed. The path attribute already exists. Java_home and classpath do not exist.
I. Click "new" and write java_home in the variable name. The variable meaning is the installation path of Java, then, write the installation path "C: \ jdk1.6" in the variable value ". (Note: If the installation path is not disk C or is not in the jdk1.6 folder, you can modify it accordingly. The following text is assumed to be installed in c: \ jdk1.6 .) 2. Find the path in the system variable and click Edit. The meaning of the PATH variable is that the system can recognize Java commands in any path, and the variable value is ".; % java_home % \ bin "(" % java_home % "indicates the value of java_home just set), or you can directly write" C: \ jdk1.6 \ bin"
3. Click "new" and then write classpath on the variable name. The variable indicates the path of the Java loading class (class or Lib). Only the class is in classpath, java commands can be recognized. The value is ".; % java_home % \ Lib \ DT. jar; % java_home % \ Lib \ toos. jar (to add. indicates the current path). If the preceding three variables are set with the same meaning as "% java_home %", click "OK" until the property window disappears, check whether the installation is successful.
Open "start"> "run", and press "cmd" to go To the DOS system interface. Then, press "Java-version". If the installation is successful. The system displays Java version JDK "1.6.0 ". Make sure that the file name on drive C is jdk1.6 and the environment variables can be copied directly. On the DOS interface, enter javac to check whether the command is legal, similarly, enter Java to check whether the command is legal. The environment variables are set. The following describes how to set path, classpth, and java_home. The following describes how to set java_home, classpath, and Path:
1. Set java_home:
1. For reference convenience, for example, if your JDK is installed in the c: \ Program Files \ Java \ jdk1.6.0 directory, set java_home to the directory path, to use this path in the future, you only need to enter % java_home % to avoid entering a long path string for each reference;
Ii. Normalization principle: when your JDK path is forced to change, you only need to change the variable value of java_home. Otherwise, you need to change any document that uses the absolute path to reference the JDK directory, if you fail to complete the changes and a program cannot find the JDK, the consequence is that the system crashes!
3. The third-party software will reference the agreed java_home variable. Otherwise, you will not be able to use the software normally. After using Java for a long time, you will know that if a software cannot be used normally, think about the problem.
2. Set classpath: This is a very interesting question, of course it is also quite difficult for beginners. The purpose of setting this variable is to find the corresponding program ". for example, compile a Java program ---. java,. class class file. If you execute Java A in the current directory, the corresponding result will be obtained (provided that you have set classpath ". "). now. when the class is moved to another directory (for example, "E: \") and Java A is executed, there will be a noclassdeffinderror exception because it cannot be found. class file,
Now you can add classpath to ".; E: \" and then run Java A to see what the result will be ~~ :)~~~, Everything is normal. The Java Command finds the. Class file through classpath!
3. Set path: the principle is very simple. Do you want to use % java_home % \ bin \ Java to execute Java commands at any time? Of course not, so, you can add % java_home % \ bin to the path. In this way, we can use Java to execute commands in any path. (When you enter your code in the Command Prompt window, the operating system will find the corresponding application in the current directory and PATH variable directory and execute.