On the function of Java_home,classpath and path _java

Source: Internet
Author: User

1, set Java_home:
first, in order to facilitate the reference
, for example, you JDK installed in the C:\ProgramFiles\Java\jdk1.7.0 directory, then set Java_home as the directory path, then you want to use this path, just enter the%java_ Home% can be, avoid each reference to enter a long path string;

second, the principle of attribution , when you are forced to change the JDK path, you only need to change the value of the java_home variable, otherwise, you have to change any of the absolute path to refer to the JDK directory documents, if you do not change the whole, a program can not find the JDK, The consequences are conceivable----system crashes!

Third, the Third-party software will refer to the agreed java_home variables , otherwise, you will not be able to use the software, the future use of Java will know, if a software is not normal use, may wish to consider whether this problem.

2, set Classpath:
This is a very interesting, of course, the problem of torturing beginners, the purpose of this variable setting is to find the appropriate ". Class" File, for example: You compile a Java program---a.java, you will get a A.class class file, You execute Java A in the current directory, and you will get the corresponding result (provided you have set Classpath to "."). Now, you move the a.class to a different directory (for example: "E:\"), execute Java A, there will be noclassdeffinderror exception, because cannot find the. class file, now you add the classpath to: ".; E:\ "again in any directory run Java A, see what will be the result ~ ~ ~:), all normal, the Java command through the classpath found. class file!

Classpath=c:\test means to go to the C:\Test folder to find the class file that needs to be executed when executing the Run command
The path cannot be specified before Java5, unless this setting: Classpath=.; C:\Test, it means first in the current directory to find the class file, if not found on the c:\test to find; (when a variable has multiple values, multiple values are separated by semicolons in English)
Set lookup from the current directory (java1.5 default): Set classpath=.

3, set path: (Must be set)
The reason is simple, you want to use%java_home%\bin\java at any time to execute JAVA commands, of course not, so you can choose to add%java_home%\bin to the path, so that We can execute commands only in Java under any path.
(When you enter your code at the Command Prompt window, the operating system looks for the appropriate application in the current directory and the path variable directory, and executes.)

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.