IDEA runs the first simple Java program (new project to run class)

Table of contents

Preface

1. Preparation work

JDK download and installation

1.IDEA download and installation

 2. IDEA establishment project

(1) New projects (Galaxy)

(2) New module (Earth)

(3) New package (country)

(4) New category (province)

(5) Create a new main method (provincial capital city)

(6) New construction method (floor)

 Run class

Extra explanation


Preface

When you first start learning Java, you will encounter many problems. You can't distinguish concepts such as classes, packages, and object methods. Many names are just one concept. If you really use multiple tests and write them a few times, you will realize it. I have always thought that It's just a fantasy, the code must be actually typed and acted upon. This article is to establish a structural thinking for friends who have just learned Java. The steps from setting up a project to creating a class are all detailed. If you have any questions, please point them out. 

1. Preparation work

To run a Java program, you must have software to run it. The commonly used software is IDEA, and there is also an environment that allows our Java program to run - KDK. These environments are the Java virtual machine. IDEA is a bow and arrow, and JDK is an arrow. Without the arrow, it cannot be used normally, so these two must be installed together.

Both JDK and IDEA are available, just skip this step.

JDK download and installation

Download the JDK11 version of JAVA from the official website (download, install, configure environment variables)_java11 download-CSDN blog

1.IDEA download and installation

Detailed steps for downloading, installing, configuring and uninstalling the idea2023 version (including tutorials on running the first java program)_idea2022_Cloud Happy Cat's Blog-CSDN Blog

 2. IDEA establishment project

(1) New projects (Galaxy)

1. Open the main menu

2. Create a new project

Creating a new project is like creating a new galaxy

ps : If you need a Chinese interface for Idea, please read this

Methods for Chinese people to understand idea_idea Chinese plug-in_Cloud Happy Cat’s Blog-CSDN Blog

3. Click on the empty project and give the project a name. The location can be customized. It is best to have all the locations in English. Then click Create

4. You can click this window or open a new window.

 

(2) New module (Earth)

The next step is to create a new earth ( module )

4. Click on the created project. Right click--New--New module

5. The name of this module can be customized, and the location does not need to be changed. Select Java as the language. IntelliJ is the system default. JDK will automatically detect your JDK and give you a choice. Generally, you don’t need to touch this, and then create

6. After creating the module, IDEA will automatically create a package and a class for you, and the method will also be written for us. Click this to run it directly, and the running results will also be displayed in the console below.

(3) New package (country)

7. The package is inside the module. Here you choose to create a new package under the src package. Of course, you can also create a new package under the module. all the same. Personal habit is to create a new one under the src package.

In the future, if you learn to be proficient, you will create a new package directly under the module. There will be no src. Now you can follow my method first.

 8. I don’t know what to name it, so let’s name it bao for now.

9. This package is created

(4) New category (province)

10. Click on the bao package, right-click--New--Class

 11. Let’s name this class aa and press Enter to create it.

 

12. Class creation completed

 

(5) Create a new main method (provincial capital city)

After the class is created, there must be an entry method to load and run the class. This is the main method, which is also the representative of a province responsible for taking the lead. Without this main, this class cannot run.

13. Type this main in the {} of the package, and there will be a prompt. Just press Enter when main appears, and IDEA will help us write the main method.

14. The main method is established. Only with this main method can the class be activated and run. Otherwise, this class will be out of luck. 

(6) New construction method (floor)

15. Write the method you want to write in the main method

System.out.println();

This is a print statement. After the content in () is run, it will be displayed on the console below. The shortcut to writing this statement is to hit soout and press Enter when prompted.

 Run class

Click this to run, and the results of the operation will be displayed below the console.

 

Extra explanation

In the previous learning of Java, if you want to write new code, you usually create a new class directly , then write the main method in the class, and then write the code you want to write in the main method. There is no main method. This The class cannot run

If you are afraid of confusion, you can create another package and then create a new class. These are all nested relationships and cannot be messed up.

Project--Module--Package---Class--main method--own method

Guess you like

Origin blog.csdn.net/m0_52861000/article/details/133327303