1. Get to know the Java VIRTUAL Machine

Information: Click here to get information about this article!

Java Virtual Machine (JVM) : The Java Virtual Machine, or JVM for short, is the imaginary computer that runs all Java programs. It is the environment in which Java programs run. It is one of the most attractive features of Java. All the Java code we write runs on it.

Cross-platform: Any software must run on the operating system. Software written in Java can run on any operating system. This feature is called the cross-platform feature of the Java language. This feature is implemented by the JVM on which we write our programs and the JVM runs on the operating system.

2. Know JRE and JDK

Java Runtime Environment (JRE) : a Runtime Environment for Java programs, including the JVM and the class libraries required by the Runtime.

The Java Development Kit (JDK) is a Java program Development Kit that contains Development tools such as JRE and compiler.

JDK > JRE > JVM

JDK installation diagram

Step 1: Download the JDK. Here is the download url, as shown below:

Step 2: Install the JDK. The diagram below:

Tips: This is the end of the JDK installation, next you need to configure the environment variables, so that you can use them.

Personal recommended configuration: Development tool: IDEA; JDK version: JDK1.8 or later

4. Configure JAVA_HOME

First win + r open the command line, enter sysdm. CPL, the result is as follows:

Then click OK all the way. The Java environment is now installed and configured. So how do you check? Run the Java -version command to view the version. If the following result is displayed, the environment is configured. Otherwise, the configuration fails. The results are shown below:

Other tutorials: Java development environment configuration for novice tutorials

5. Write introductory programs

With the development environment set up, we are now ready to develop our first Java program. Java program development three steps: write code, compile, run. Now, let’s do the first step: write the code. Create a new helloWorld.java file on your desktop and write the following code:

public class HelloWorld {
    public static void main(String[] args) {
        // In IDEA, Alt + 4 is the shortcut key of console
        System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
        System.out.println("Hello World!");
        System.out.println(This is my first Java program!);
        System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *"); }}Copy the code

Step 2: Compile HelloWorld.java. Compilation means translating the Java source files we write into class files that the JVM recognizes. During this process, the compiler will check if there are any errors in the program we have written. If there are any errors, the compiler will indicate them. If there are no errors, the program will compile successfully. Open the CLI and run the following command to compile the file. The diagram below:

Step 3: Run the code. Running means handing the bytecode file to the JVM to execute, and our program runs. The diagram below:

1. Tip: Compiling and running code on the command line is a bit of a hassle. After compiling and running with IDEA development tools, you no longer need to use the command line to operate.

Main method: called the main method. The format is fixed and cannot be changed. The main method is the entry point or starting point for the program, and no matter how many programs we write, the JVM will start executing from the Main method. Note here: Do not write mian, as it is easy to make mistakes when you are just learning.