- Understanding of environmental variables
Environment variables (environment variables) are typically used in the operating system to specify the operating system environment of some parameters, such as: temporary folder location and System folder location.
An environment variable is an object with a specific name in the operating system that contains the information that one or more applications will use. For example, the PATH environment variable in Windows and DOS operating system, when the system is required to run a program without telling it the full path of the program, in addition to the current directory in the search for this program, but also in path specified in the path to find. The user can run the process better by setting the environment variables.
- Java environment variable Configuration
The Java Execution Environment (JDK) is itself a platform, and the program executed on this platform is a compiled Java program (later, after the Java program is compiled, it will exist as a. class file). If the Java execution environment is likened to an operating system, if the path variable is set up to allow the operating system to find the specified utility (the. exe file is found in Windows), the purpose of setting up classpath is to have the Java execution Environment locate the specified Java program ( That is the. class file).
Program parsing :
First write the Java source Code program, extension. java;
In command-line mode, enter the command: Javac source file name. Java, compile the source code, generate a. class bytecode file;
After compiling, if there is no error message, enter the command: Java HelloWorld, the class bytecode file interpretation run, do not need to add the. class extension. See:
That is: the JDK (Java Development Kit) Java Development Package is installed after the installation of the Java program to provide the environment to run, This environment can only execute. class files, and. Class executables are generated by the. Java source file, and the execution is done through Java.exe, and the compilation is done through the Javac.exe, and the two files are placed in the JDK installation directory, just like installing a cool dog, when the computer performs the cool dog installation Directory of Kugou.exe files, in the same way, if you do not specify the computer Java.exe and javac.exe the installation directory of the two files, is unable to identify the JDK to complete the compilation and execution of the program.
Thus: The path variable must specify two, a Javac.exe file (c that is Complie), where a Java.exe file is located, as shown in:
Path=c:\java\jdk1.8.0_131\bin;c:\java\jdk1.8.0_131\jre\bin, because the JDK installation directory is long, in order to see the ease of understanding, we have the JDK installation directory is habitually named Java_home, namely: Java_home=c:\java\jdk1.8.0_131,path=%java_home%\bin;%java_home%\jre\bin; in PC-Properties-Advanced system settings-environment variables-new system variables, new Java_ Home,path Two System variables:
In addition to the Java_home and path two environment variables, the. class file is executed to require some class or package, the purpose of setting up classpath is to tell the Java execution Environment, In which directories you can find the classes or packages that you need to execute the Java program: Classpath=.; %java_home%\lib\dt.jar;%java_home%\lib\tools.jar
So the summary is: the Java environment variable needs to set three:
JAVA_HOME=JDK installation directory
Path=javac.exe exists path; Java.exe exists path
The class or package required by the Classpath=java program
-
the role of the PATH environment variable--Help the system operate Java
We use Javac to compile the source code into a. class file, which is called by the Java command to be executed by the program.
The
question is: How did the system find and invoke Javac.exe and Java.exe two applications?
For example, usually we run a program, such as Warcraft, cool Dog music, are the first to find their application War3.exe and Kugou.exe location, and then double-click Run. So how does the operating system automatically find the location of Javac.exe and Java.exe?
-
Classpath The role of the environment variable--tells the Java virtual machine all the executable files. Where is the class The value of
is also made up of directories, which are used to tell the Java execution Environment which directories can find the classes or packages needed to execute the Java program.
For example, if I want to run a file named Test.class, and this program invokes the contents of another Link.class file, the system must know the location of the Link.class file to invoke the Link.class file. If the directory of the Link.class file is in the value of the CLASSPATH environment variable, you can find it.
-
java_home environment variable---makes the configuration of other related environment variables more convenient and concise
The
Java_home is generally set to the JDK's installation directory, such as C:\Program files\java\jdk1.6.0_22. If Java_home is set, the PATH environment variable can be configured as "%java_home%\bin".
Detailed installation configuration steps see: https://jingyan.baidu.com/article/4ae03de320d99f3eff9e6bfd.html
Java environment variable understanding and configuration