Java Fundamentals-Environment variables (PATH) and class variables (CLASSPATH)

Source: Internet
Author: User

I. environment variable (PATH)

Under Popular science, environment variables are not knowledge of Java, but are environment variables of Windows system.

Below, see how to view and modify environment variables for Windows

After the "My Computer" right-click Property enters

Click "Advanced System Settings" (for example):

To bring up the System Properties dialog box, click Environment Variables:

Enter the Environment Variables Properties dialog box with user and system variables (two different: User variables are valid only for the current user, system variables are valid for all users)

I used only valid for the current user, that is, Johnson this user function;

Click the "Path" property to pop up the dialog box:

1. Change the variable named path "variable Value" to:%java_home%\bin;%java_home%\jre\bin

If you do not have a path variable name, create a new one.

(Percent of meaning dynamically gets the median path value, for example:%java_home% represents the path corresponding to the variable name of the dynamic get Java_home)

2. Create a new variable named "Java_home", the variable value to write your JAVA installation directory, my installation in the "C:\Program files\java\jdk1.8.0_25" this path. such as

Is my Java installation directory

Here, Java's path path is already set.

After you open the CMD console (Dos), you can open the Java binary executable program in any directory (for example: Java.exe,javac.exe);

(The principle is that the Windows system will look for Java.exe in the current directory, and will go to the variable you set if you don't find it.)

I set the variable is "%java_home%\bin;%java_home%\jre\bin", "%java_home%" This part of the system will be dynamically obtained as "C:\Program files\java\jdk1.8.0 _25 ",

So the system finds the Java.exe program according to the path of "C:\Program Files\java\jdk1.8.0_25\bin;%java_home%\jre\bin". )

Second, class variables (CLASSPATH)

Note: Class variables are for Java executable program (Java.exe), regardless of operating system (PATH variable is system-specific, Java-independent, to be clear)

1. Go to the "Environment variable" (same path operation) as:

2. Create a new variable name for classpath, and the variable value is: ".; %java_home%\lib;%java_home%\lib\tools.jar ", such as:

(Note: The variable value is preceded by ".;", with no semicolon at the end--)

At this point: Classpath setup is complete.

Principle: When the Java program runs, it looks for the bytecode file in the specified environment variable value, and does not find it in the current directory of the CMD console.

Example: Run

1.

, Java.exe will only be in the first few paths I set up the search;

2. Premise: The variable value at the end of the case with a semicolon (no semicolon ";") Only run Step 1), not found in the Classpath path will be looked up in the current directory.

Java Fundamentals-Environment variables (PATH) and class variables (CLASSPATH)

Related Article

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.