Installing the JDK requires setting the system environment variables, including the Java_home,classpath,path, where Java_home is the path to install the JDK, mainly for the convenience of writing the path later, with no real meaning. Path is set to the paths of common Java tools, including Java,javac (in .../bin), which is primarily convenient for each time we use this tool, we do not need to write out the full pathname of the tool. Classpath is the path that needs to be searched when executing the. class file with the Java command, which is where to find the. class file that we need to execute. Here is an example to illustrate classpath.
I created a new folder on my desktop test, which contains SRC and class two folders, where SRC is used to store the. java files we write, and class is used to store the compiled. class file.
Test |_SRC |_class
When you write down Improt java.util.*, when the compiler faces the import keyword, you know you want to introduce java.util the class in the package, but how does the compiler know where you put the package? So you first have to tell the compiler where the package is located, and how do you tell it? is set classpath) if java.util this package in C:\jdk\ directory, you have to set c:\jdk\ this path to Classpath! When the compiler faces the import java.util.* this statement, it first looks for the directory specified by Classpath and checks to see if the subdirectory java\util exists, and then finds the compiled file (. class file) that matches the name. If you do not find it will be an error!
After reading the above introduction, I think we should understand the role of environmental variables, you will know why it is necessary to configure, rather than only know the need to configure.
Explanation of system environment variables