Java Basic Learning--1.3 about Java environment variable setting Path,java_home,classpath

Source: Internet
Author: User

After you install the JDK, set the Java environment variable.

when I first approached, I was confused, what the hell is this, and then I don't know what the reason is.

Follow the instructions to finish and do not know why to do so, here simple to do some summary instructions.

First, what is an environment variable

an environment variable is a parameter that is used in the operating system to specify the operating system environment .

Actually, it's almost like the variables in the program.

A variable in a program is a short string that represents a string of characters that have meaning in the program.

The environment variable is the variable that is used in the operating system.

As to what these variables do, it is related to the specific variable name.

So, let's introduce the three environment variables we're going to set.

①path: Is the default path of the operating system that runs the program without the specified location.

There are two procedures for executing a Java class with a command

The first one is Javac can compile Java source files into class bytecode files

The second is that Java can run a class bytecode file

These two instructions are actually running the following two applications.

C:\Program Files\java\jdk1.7.0_79\bin\javac.exe

C:\Program Files\java\jdk1.7.0_79\bin\java.exe

we append "to the existing environment variable path"; After the C:\Program files\java\jdk1.7.0_79\bin" ,

When we execute javac Helloworld.java , we do not need to specify the location of the instruction Javac,

Because the operating system will automatically go to the " C:\Program files\java\jdk1.7.0_79\bin" defined in path to find Javac.exe and then execute

This can be very cumbersome to write, and many tools such as Tomcat often use the contents of the JDK,

So we add the following custom environment variable to the system environment variable

②java_home:

put Java_home The installation path (such as C:\Program files\java\jdk1.7.0_79) that is set to the JDK, which includes folders such as Lib,bin,jre, when We need the Java path when you write%java_home% on it, without having to enter a long list of addresses.

It becomes a "; %java_home%\ bin"

In this case then execute the javac command to see the effect (the specific setting method refer to the previous blog)

Successful execution without specifying the path of the Javac

③classpath: The path to the Java Run Environment load class.

The previous data said that only classes in Classpath can be identified and loaded,

Set to .; %java_home%\lib (Note the preceding dot (.), the point number represents the current path).

However, it is said that jdk1.6 above will not need to configure the CLASSPATH, the system will automatically help you configure, only need to configure Java_home and path is OK.

Accreditations, let's try it.

Now I have not configured calsspath in my environment

I can do that.

In addition, if you install the JDK, you can run Javain the command line, or CMD, without configuring any environment variables, because when you install the JDK, you go to C:\windows\ System32 copy a Java.exe file, so cmd can run, you must ensure that Javac in the command line anywhere can run, just calculate java_home and path configuration pair!

There are also system environment variables that seem to be case insensitive.

Add my test program again, the most elementary Helloworld.java

 Public class HelloWorld {    publicstaticvoid  main (string[] args) {        System.out.println ("Hello world!" );    }}

End.

Java Basic Learning--1.3 about Java environment variable setting Path,java_home,classpath

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.