Three environment variables need to be set in java (there is no need to set classpath after 1.5, but I strongly recommend that you continue to set it to ensure backward-side-use issues)
After the JDK installation is completed, we will set the environment variables: right-click "My Computer", select "Properties", select "Advanced" label, enter the environment variable settings, and set the following three environment variables:
(1) Configure path variables:
Why configure path variable?
Because the computer system will find some programs needed in java programming based on the value of this variable, such as javac.exe, java.exe, javah.exe, etc., where the javac.exe program is used to compile java source code, and the java.exe program is used to execute code with the suffix class.
How to configure path variable?
path variables are generally created by computer systems, so there is no need to create a new variable. Just select the path variable in the system variable and click "Select" -> "Edit". It should be noted that you should not delete the original path values in the box casually. Instead, add a semicolon after the large string of values, and then fill in C:/Program Files/Java/jdk1.5.0_17/bin. The key-value pairs are listed below:
Variable name: PATH (case insensitive but recommended to use uppercase)
Variable value: C:/Program Files/Java/jdk1.5.0_17/bin
(2) Configure classpath variable:
Why configure classpath variable?
Only by configuring the classpath variable can the java interpreter know where to find standard class libraries. These standard class libraries have been written by others, so we just use them. For example, we often use classes in the java.lang package, which are set as default import after configuring the classpath variable, so we don't need to import the package when writing programs. So where are these standard library? In the files suffixed by jar in the lib directory of JDK: one is dt.jar and the other is tools.jar. Both jar packages are located in the C:/jdk1.6.0/lib directory, so we usually add these two jar packages to our classpath environment variables. The values of the values are: .; C:/Program Files/Java/jdk1.5.0_17//lib/tools.jar; C:/Program Files/Java/jdk1.5.0_17//lib/dt.jar;
How to configure classpath variable?
Click New Classpath in the column of system environment variables. The specific process is omitted. Only its key-value pairs are listed below:
Variable name: CLASSPATH
Variable value: .;%JAVA_HOME%/lib/tools.jar;%JAVA_HOME%/lib/dt.jar;
(Note that there is a "." at the beginning of CLASSPATH, indicating the current directory. Using two % to surround the JAVA_HOME variable means referring to the value of the variable. Of course, if you don't want to do this, you can also configure the value of the classpath to be: .;%JAVA_HOME%/lib/tools.jar;%JAVA_HOME%/lib/dt.jar; that is, replace %JAVA_HOME% with the value of the JAVA_HOME variable);
(3) Configure the JAVA_HOME variable:
Why configure classpath environment variables?
First, for the convenience of reference, for example, if JDK is installed in the C:/Program Files/Java/jdk1.5.0_17 directory, set JAVA_HOME as the directory path. Then when you want to use this path in the future, you only need to enter %JAVA_HOME% to avoid entering a long path string every time you refer to it;
The second is the principle of normalization. When the JDK path changes, you only need to change the variable value of JAVA_HOME. Otherwise, you need to change any document that uses an absolute path to refer to the JDK directory. If it is not changed completely, a program cannot find the JDK, the consequences are conceivable-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Third, third-party software will reference the agreed JAVA_HOME variable, otherwise, you cannot use the software normally.
How to configure JAVA_HOME variable?
Click New JAVA_HOME in the column of the system environment variable (JAVA_HOME points to the installation path of JDK), and the value of the variable is actually the root directory of the JDK installation path. The specific process is omitted, and only its key-value pairs are listed below:
Variable name: JAVA_HOME
Variable value: C:/Program Files/Java/jdk1.5.0_17
Test whether the JDK is installed successfully
Enter cmd in run
Then enter java version
See if the Java version you configured can be displayed
The above is the Java environment variable configuration process and why the path variables, classpath variables, and JAVA_HOME variables are configured. I hope this article will be helpful to everyone's learning.