PATH system environment variable configuration tutorial [graphic steps]

To develop Java programs, you need to use the development tools provided by JDK (such as javac.exe, java.exe and other commands), and these tools are in the bin directory of the JDK installation directory. If you do not configure environment variables, then these commands can only be used in this Execute in the directory. It is impossible for us to put all java files in the bin directory of JDK, so the role of configuring environment variables is to enable java-related commands in the bin directory to be used in any directory.

PATH environment variable

The PATH environment variable is used to save the paths of a series of commands (executable programs), each path is separated by a semicolon. When running a command in the command line window, the operating system will first search for the executable file corresponding to the command in the current directory. If not found, the operating system will continue to search for the file in the path defined in the PATH environment variable. If it is still not found, the system will report an error. The steps to configure the system PATH environment variable are as follows.

(1) View the environment variables in the Windows system properties

Right-click Computer on the desktop→Properties, select the "Advanced System Settings" option on the left side of the pop-up system window, the system properties dialog box will pop up, click the "Environment Variables" button under the "Advanced" tab of the system properties dialog box, The "Environment Variables" dialog box pops up.

Environment variable popup

Step 2: Set the PATH system environment variable

In the system variable dialog box, select the system variable named PATH from the system variable area, click the "Edit" button, and the edit environment variable dialog box on the right will pop up.

Set the PATH system environment variable

Click the "New" button and add the path where the javac command is located in the pop-up input box, for example, C:\Program\FilesVava\jdk-11.0.11\bin

Set the PATH system environment variable

Step 3: View the PATH system environment variable

Open the command line window and execute set to view the variable value of the PATH variable in the PATH command after setting. The path information of the javac command is displayed in the environment variable.

insert image description here

Step 4: Verify the PATH system environment variable is set

Execute the javac command in the command line window. If the help information can be displayed normally, it means that the system PATH environment variable is configured successfully, and the system will permanently save the PATH environment variable settings.

Verify the PATH system environment variable is set

Introduction to CLASSPATH environment variable

The CLASSPATH environment variable is used to save the path of a series of class packages, and it is viewed and configured in exactly the same way as the PATH environment variable. When the Java virtual machine needs to run a class, it will look for the required .class files and class packages under the path defined by the CLASSPATH environment variable.

In order for the Java virtual machine to find the required class file, it is necessary to set the CLASSPATH environment variable and save the HelloWorld.class file path. Execute the following command in the command line window.

set CLASSPATH=C:\Program FilesVavaljdk-11.0.11\bin

After executing the above command, execute the java HelloWorld command again to run the program.

The result of running the command:

Execute the java HelloWorld command to run the program, and the result is shown in the figure below.

command run result

As can be seen from the figure above, the Java HelloWorld command runs successfully and outputs the result of "hello world". After setting the CLASSPATH in the command window, the program will search for the class file in the specified directory according to the CLASSPATH setting. Therefore, although there is no HelloWorld.class file in the root directory of the C drive, the Java HelloWorld command can still be executed correctly.

Guess you like

Origin blog.csdn.net/cz_00001/article/details/132457541