How the Java environment variable is configured

Source: Internet
Author: User

When we are learning Java, we must first configure the Java environment variables, perhaps you do not understand what is the Java environment variables, we do not need to understand, you just know, the Java environment variable configuration, your computer can compile and run Java program, which is obviously what you want, OK, Please do it with me below!

1. First, we need to download the JDK installation package, which you can load on www.sun.java.com

2. Then install the JDK, select "Development tools" during installation and remember the location of the JDK installation.

As this is relatively simple, do not explain.

3. After the installation is complete, open My Computer---> Properties panel

Select Advanced system Settings

4. Select Environment Variables

5. Set the system variable in this block

New system Variable

Variable name Java_home

Variable Value D:\Program files\java\jdk1.8.0_101

Special Note: My JDK is installed in this location D:\Program files\java\jdk1.8.0_101 so just fill this out, where your own JDK is installed, just fill it out!

Variable name CLASSPATH

Variable value D:\Program files\java\jdk1.8.0_101\lib\dt.jar;d:\program Files\java\jdk1.8.0_101\lib\tools.jar;

Locate the Path selection Editor in the system variable:

Add D:\Program files\java\jdk1.8.0_101\bin at the end;

Special note: In the last add, do not put the default delete Oh! If deleted, your part of the program will not be able to run Oh!

6. Verify that the environment variable is configured successfully

In " accessories " Find " run ", enter "cmd"

Re-enter Java

If you have the following interface instructions you have configured! Your computer can run Java programs.

No matter which language you learn, the first HelloWorld program runs successfully, representing your learning has stepped into a small step. Before doing this Java experiment, the reader must install the JDK (including the configured environment variables) at least on his or her computer, and if the reader does not install the JDK and configure the environment variables, it can be considered another experience for the user.

Write and save the code. Open Notepad to write 1 code, Figure 1 Code is (note input code when the IME must switch to the English input state):

 Public class HelloWorld {    /**    * Output line string "Hello world!"     @param args     */     Public Static void Main (string[] args) {    System.out.println ("Hello world!" );    }}

Set up a Java folder in the D drive to save the code, be sure to keep in mind, 2, "Save Type (T)" To select "All Files (*. *)", "File name (N)" must be Helloworld.java. As shown in 3, after saving to D:\JAVA under Check the file name is correct, Helloworld.java.txt,helloworld.txt is the wrong file name. The Java program code suffix is. java, and file names often require consistency with the class name. The Java language is strictly case-sensitive, but the name of Windows is not case-sensitive.

Start a command prompt and go to the D:java folder. 1, press the WIN+R key to start the Run Command box, enter the cmd command, and then start the Command Prompt window. Then enter the following command in the Command Prompt window to enter the D:java directory:

>d: < Enter >

>CD JAVA < Enter >

Call the compile instruction Javac convert Helloworld.java to bytecode file Helloworld.class. As shown, execute the instructions:

>javac Helloworld.java < return >

Execution instructions If you don't know what information is the best information, check the Java folder to find a more. class file, which is the bytecode file. If you are prompted for an error message, you should check back. First check that the JDK environment variables are configured, and then check that the class name and file name are the same, and then check that the code is useful for body input input and so on.

Run the program. After the code is converted to a. class file, it can be run under the JVM virtual machine. At the command prompt, you typed the command:

>java HelloWorld < return >

, print output after carriage return:

helloworld!

Note that this is actually running Helloworld.class, but the command does not use the suffix name.

Analyze the pseudo-compilation principle of the third step. , the. Java suffix is the source code, one or more source code to be produced by the Java compiler. class suffix bytecode. Bytecode is non-platform-independent, and the C language compiler generated platforms related to the machine code is not the same. The machine code can only be executed on the corresponding platform, and bytecode execution is platform independent, but there must be an interpreter.

Analyze the execution process of the fourth Java program. The figure is interpreted as a process of platform-related machine code execution after the. class file is read. and the compiler language (such as C) The biggest difference is that the Java program through the interpreter to the platform related to the machine code to execute, it can be seen in the process of dynamic interpretation, and the compiler language (such as C) is compiled before the implementation of the Peace Platform related machine code. This is also an important reason why the Java language can "compile and run" once (pseudo).

How the Java environment variable is configured

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.