Configuration of Java Environment variables

Source: Internet
Author: User
Tags tomcat server

I. Configuring the environment variable path

In Java development, in order to compile, run the program, often use Javac, Java and other commands, then what exactly are these two commands? In order to find out, we went to the JDK to look for.

By looking, they are finally found in the D:\Java\jdk1.7.0_51\bin (JDK installation directory, which may be different). You will find that Javac and Java commands are essentially two EXE files.

in the previous blog analysis of Windows system environment variables, to facilitate the launch of EXE files in any directory, you need to configure environment variables. Now, then, configure the environment variables for Java. Detailed steps in the context of the Windows System environment variables have been very thorough, here will not repeat. Configure the D:\Java\jdk1.7.0_51\bin in path.

So far, the environment variables have been completely configured.

(can skip) and look at D:\Java\jdk1.7.0_51\bin, we sometimes move the JDK to another disk (such as the e-drive), then it becomes E:\Java\jdk1.7.0_51\bin, or we'll rename the jdk1.7.0_51 to jdk1.7. All in all, D:\Java\jdk1.7.0_51 is easy to change (the bin directory is not going to change it), and in order to make it easier to use the Tomcat server later, we need to extract the D:\Java\jdk1.7.0_51 separately into a variable, Changes in the future only need to change the variable, without the need to change path.

A. Create a new Java_home variable and assign the value to D:\Java\jdk1.7.0_51;

B. Modify the D:\Java\jdk1.7.0_51\bin in path to%java_home%\bin.

OK, the environment variable path is configured. Try to start Javac.exe in any directory.

Successful startup of Javac.exe under C:\Users\lenovo indicates a successful configuration.


Second, configure the system variable Classpath

The use of C, C + + and other languages written by the program will generate EXE files, then Java generated is also EXE file? The answer is no, Java generates a class file that cannot be started by double-clicking, and only started with Java commands. So, the same question, can you start it in any directory with a Java command?

The answer is no doubt, as with the EXE file, just configure an environment variable (CLASSPATH).

Create a new variable and assign it the same directory as the class file (for example, on the e-drive).

OK, here's the test, there's a class file under the E disk that executes the command.


Third, the current directory and environment variable configuration of the directory is the first

Assuming that the environment variable is configured with E:\, there is a Test.class file under the E and F disks, but their output is different, the E-drive outputs "I am the file of the directory where the environment variable is configured" and the F-drive outputs "I am the file of the current directory." Now that the directory is F, what would the result be if you typed Java Test?

The results show that the class file under the E-drive (the directory where the environment variable is configured) is executed. At this point, if you delete the Test.class file under E, type Java Test into the F-disk, what will the result be?

The results show that the Test.class file is executed under the F disk (current directory).

Summary: For the class file, in contrast to the EXE file, the environment variable is configured in the directory to find the file , the existence of the execution; otherwise go to the current directory to find .


Four, say a little spoof

First look at the film,

As can be seen from the picture, I first deleted the E-disk under the Test.class file, and then to the F-drive test file, the difference is that two times the environment variable configuration is not the same, the environment variable is the only difference between a semicolon, a semicolon, a No. Will find the results quite different.

In fact, add a semicolon, will go to the environment variable configuration of the directory to find the file, the lookup is executed, does not exist in the current directory down to find execution, and no semicolon will only find the file in the environment variable, find the execution, otherwise it will end directly.



Configuration of Java Environment variables

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.