Java environment variable configuration and Java environment variable configuration
1. Configure the environment variable path
In Java Development, javac and java commands are often used to compile and run programs. What are the two commands? To make it clear, go to jdk to find it.
Through searching, we finally found traces of them in D: \ Java \ jdk1.7.0 _ 51 \ bin (jdk installation directory, may be different. The javac and java commands are essentially two EXE files.
In the previous blog's analysis of Windows system environment variables, I mentioned that to enable the EXE file in any directory, You need to configure environment variables. Now, configure environment variables for java. The detailed steps have been thoroughly explained in the analysis of Windows system environment variables, so I will not go into details here. Configure D: \ Java \ jdk1.7.0 _ 51 \ bin to path.
The environment variables have been fully configured as of above.
(Skip) Let's look at D: \ Java \ jdk1.7.0 _ 51 \ bin. Sometimes we move jdk to another disk (for example, an E disk) and then E: \ Java \ jdk1.7.0 _ 51 \ bin; or we will rename jdk1.7.0 _ 51 to jdk1.7. All in all, D: \ Java \ jdk1.7.0 _ 51 is very easy to change (the bin directory will not change it). To facilitate future use of the Tomcat server, we need to set D: \ Java \ jdk1.7.0 _ 51 is extracted separately and put into a variable. After that, you only need to change the variable without changing the path.
A. Create a JAVA_HOME variable with a value of D: \ Java \ jdk1.7.0 _ 51;
B. Change D: \ Java \ jdk1.7.0 _ 51 \ bin in path to % JAVA_HOME % \ bin.
Now, the environment variable path is configured. Try to launch javac.exe in any directory.
If javac.exe is successfully started under C: \ Users \ lenovo, the configuration is successful.
Ii. Configure the system variable classpath
If an EXE file is generated by a program written in C, C ++, and other languages, does java generate an EXE file? The answer is no. java generates a class file and cannot be started by double-clicking. It can only be started by using java commands. So the same problem arises. Can I start it using java commands in any directory?
The answer is yes. Just like the EXE file, you only need to configure an environment variable (classpath.
Create a variable and assign it to the directory where the class file is located (for example, on the edisk ).
Okay. Let's check that there is a class file under the e drive and execute the command.
3. The current directory and the environment variable configuration directory
Assume that the environment variable is configured with E: \, and there is a Test under drive E and drive F. class file, but their output results are different. The E disk outputs "I am the directory file for environment variable configuration", and the F disk outputs "I am the file of the current directory ". The current directory is drive F. If you type java Test, what is the result?
The results show that the class file under the e drive (environment variable configuration directory) is executed. In this case, if you delete the Test. class file under drive E and type java Test under drive F, what will the result be?
The result shows that the Test. class file under drive F (current directory) is executed.
Summary: for the class file, unlike the exe file, the file will be searched in the environment variable configuration directory and executed if it exists; otherwise, the file will be searched in the current directory.
4. Spoof
First watch the film,
As you can see from the picture, I first deleted Test. class file, and then start the Test file on drive F. The difference is that the environment variable configuration is different during the two executions. The only difference between the environment variables is a semicolon and a semicolon, none. The results are quite different.
In fact, if you add a semicolon, you will first find the file in the environment variable configuration directory and execute the search. If it does not exist, you will find and execute it in the current directory; if the number is not added, the system will only search for files in the environment variables and execute the search. Otherwise, the process ends directly.
Zookeeper