Briefly describe the meaning of configuring the environment variable path and the difference between path and classpath


Preface

 After we learn Java and install JDK, there will be an operation to configure environment variables. Or when we learn other languages ​​and use other software tools, we will configure environment variables according to the tutorial. So, why configure environment variables?

1. JDK bin directory

 After we install the JDK, there are many subdirectories under the installation directory, among which the bin directory stores commands related to running Java programs. Among them, files with the .exe suffix are executable files, or command files.

Insert picture description here

Second, the role of configuration environment variables

 When we finish writing a java source program, we need to use the javac command to compile the source file. If we do not configure environment variables and cannot be used directly in the DOS command window, the system will prompt " This command is not an internal or external command, nor is it an executable program or batch file ." It means that the windows operating system does not have a javac.exe file.

 At this time, we need to switch the directory to "C:\Program Files\Java\jdk1.8.0_91\bin", which is the directory where the javac.exe file is located, so that the javac command can be executed.

 So we came to the conclusion that by default the Windows operating system searches for executable command files from the current path . So, it means that we need to switch to the bin directory every time we use the javac command. Isn't this troublesome?

 But we found that in the C:\Users\Administrator> directory, using the dir command and unable to find the ipconfig.exe file, but you can execute the command in this directory. The ipconfig.exe file is actually under C:\Windows\System32. The reason why it can be executed directly without switching to the directory is because the environment variable path in the windows system is working.

Bold style
 Therefore, in order to make the javac command usable in any directory, we only need to configure the C:\Program Files\Java\jdk1.8.0_91\bin path to the environment variable path .

**

to sum up

 All in all, we understand that the purpose of configuring the system variable path is to allow certain commands to be used in any directory. We right click on the computer -> properties -> advanced system settings--> environment variables

Insert picture description here
 Among them, configuring user variables means that it is only valid for the current user, and configuring system variables means it is valid for all users of the computer.

 We learn java to know the path of classpath, which refers to the class search path, configured

.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\bin

 Among them, dt.jar is the class library about the operating environment, and tools.jar is the tool class library. It is set in the classpath so that the JVM can find these required dependencies according to the path. In other words, the JVM finds the class through the classpath .class files .

The difference between the two

 The path environment variable belongs to the windows operating system, not to the category of java. It is the path basis for the windows system to search for a certain command file.

 The classpath environment variable does not belong to the windows operating system. It is a mechanism in the java programming language. This mechanism is designed to provide a path basis for the class loader to load class files.

Guess you like

Origin blog.csdn.net/m0_46988935/article/details/109984784