Java development environment configuration under Windows 10

JVM introduction

The Java runtime machine needs to be run based on the JVM (Java Virtual Machine). Java is neither a purely compiled language nor a purely interpreted language, but like other languages, the program needs to be run from source code to bytecode and then to run. Compile and execute afterwards.

JVM can be used as an interpreter to execute the compiled bytecode of Java. Normally, as an interpreter, different platforms have different bytecode-oriented interfaces. If you want to achieve compatibility, you need to perform a converter. Execute after conversion. The JVM here also acts as a converter, making Java a better platform portability

Install JDK

The full name of JDK is Java SE Development Kit, Java Standard Edition Development Kit, which contains various tools and resources required for Java programs, including Java compiler, Java Runtime Environment (JRE), and commonly used Java libraries.

If you want to develop Java programs, we need to install JDK, if you just run Java programs, installing JRE is enough

JDK download link: https://www.oracle.com/java/technologies/javase-downloads.html

Currently the latest version of Java has been updated to 14; click the download link on the page:

Snipaste_2020-06-11_14-27-58.png

According to your computer system, select the appropriate version to download the installation package:

Snipaste_2020-06-11_14-29-11.png

When installing, follow the prompts to install (next step, next step), if you choose the storage directory, you can customize or default;

3. Configure environment variables

Before the official use, we need to configure the Java environment variables:

1. Open the environment variable, search for "environment" in the Win10 search bar, select the environment variable option, and open the environment variable panel

QQ screenshot 20200611143735.png

2. Under User Variables, click New to create a new user variable JAVA_HOME and fill in the JDK installation path.

Snipaste_2020-06-11_15-58-06.png

3. Create a CLASSPATH in the same way as 2. The variable values ​​are as follows (note that there is a. Symbol at the top):

.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;

Snipaste_2020-06-11_15-01-39.png

4. Open Path and add the following path name to the line by line;

%JAVA_HOME%\bin
%JAVA_HOME%\jre\bin

Snipaste_2020-06-11_15-04-16.png

After completing the above operations, open the command line (run as an administrator) and enter java -version; the following similar output appears, indicating that the environment has been configured successfully:

Snipaste_2020-06-11_15-06-26.png

Here we need to explain why user variables are set but not system variables. Setting user variables means that this setting is only for this user and does not affect other users (this feature is very important for multiple people using a machine); The configuration of system variables is effective for all users who use this system.

4. Hello World instance test

The last step, Hello World code test,

First open an empty txt text, fill in the following code, and save it with a .java suffix, such as Hello.java (declare it, I entered public class Demo in the code below, in order to keep the class name and file name consistent, (So ​​the pictures of the examples given are named after Demo)

public class Hello{
    
    
    public static void main(String [] args) {
    
    
        System.out.println("Hello World");
    }
}

Note: Before operating the previous step, you need to open the display suffix option set by the file manager:

Snipaste_2020-06-11_15-16-09.png

Then open the command line, cd to the saved java file path, enter javac Hello.java (replace with the java file name you saved) to compile, a class file will be generated in the same directory

Snipaste_2020-06-11_15-52-27.png

Then enter java Hello and the program will run:

Snipaste_2020-06-11_15-50-16.png

The article was first published in the public account for Java development enthusiasts , a Java rookie who likes to share!

Guess you like

Origin blog.csdn.net/weixin_42512684/article/details/106696311