IntelliJ IDEA's HelloWorld project creation and related configuration file introduction

In the blog post "  Introduction to the User Interface of IntelliJ IDEA  ", we have a general understanding of the user interface of IntelliJ IDEA by creating a Static Web project. Next, taking advantage of this enthusiasm, let's create the first Java project "HelloWorld", enter The following interface:

1

As shown in the figure above, click Create New Projectto enter the following interface:

2

The above interface, we have introduced in the previous blog post, here, we select "Java" -> "Java EE" to create the project, and then focus on the "Project SDK" pointed to by the first red arrow ", which means that we will use the SDK in the next project. To set it up, we need to download the JDK in advance!

So how to download and install the JDK? Don't be afraid, in the blog post "  How to Install JDK and Configure Environment Variables in Win10 System  ", we have demonstrated the specific operation process. Take Win10 as an example, and Win7 is the same. Next, click "New" behind "Project SDK" to set the JDK:

3

As shown in the figure above, IntelliJ IDEA selects its own JRE by default, and we choose the JDK downloaded in advance, as shown in the following figure:

4

As shown in the figure above, we only need to locate the "  jdk 1.8.0_121  " directory, and then click "OK" to confirm:

5

As shown in the figure above, it shows what it looks like after selecting JDK. Click "Next" to go to the next step:

2

  • Note 1: Command Line AppA class with a main method will be automatically created;
  • Note 2: Java Hello WorldA class with a main method will be created automatically and will print out Hello World.

As shown in the figure above, you can choose to Create project from templatequickly create a project. Here, we do not check the use template, create it manually, and click "Next" to enter the following interface:

3

As shown in the figure above, enter the project name, and do not need to modify "More Settings", just click "Finish" to enter the following interface:

4

  • Note 1: Project structure diagram;
  • Callout 2: External Libraries.

As shown in the figure above, in the project structure diagram, the srcdirectory is Source root, we generally create packages and classes in this directory; in the external library, the JDK 1.8 version we imported is displayed. Next, we srccreate packages and classes in the directory:

5

As shown in the figure above, move the mouse to the srcdirectory, then right-click, select "New", and then select "Package" to create a package:

6

As shown in the figure above, we enter the package name "  com.hit.demo  ", which is separated by dots in English state ., indicating that multiple packages are created at one time. The specific effect is shown in the following figure:

7

  • Note 1: Multiple empty packages are stacked together;
  • Mark 2: gear symbol, generally means setting;
  • Note 3: Choose whether to stack empty packets together.

As shown in the figure above, the multiple empty packages we created are overlapped by default. If one of the packages is not empty, the package will be automatically unpacked. Here, if you feel uncomfortable stacking empty packages together, you can click   the gear button shown in  mark 2 , and then click  "  Hide Empty Middle Packages " shown in mark 3  to remove the checkmark and change it to "  Compact Empty Middle Packages  ", The effect is shown in the following figure:

8

Next, select the "demo" directory, click the right side of the mouse, and select "Java Class" to enter the following interface:

9

如上图所示,将类名(Name) 设置为“ HelloWorld ”,一般情况下,如果类名出现多个单词的话,则每个单词的首字母都大写。类创建完之后,在编辑区敲入代码,如下图所示:

10

接下来,在“编辑区”点击鼠标右键,选择Run 'HelloWorld.main()',运行后,结果如下图所示:

11

  • 标注1:运行结果“HelloWorld!”
  • 标注2:存放 Module 编译文件的 out 目录。

在这里,对于 标注1 所示的内容,毫无疑问,其为在控制台上的输出语句;对于 标注2 所示的内容,则需要咱们留心啦,其存放的是项目中所有 Module 的编译文件。如果咱们细心一点的话,则会发现outsrc目录的层次结构完全相同。

最后,咱们在来了解一下项目中的相关配置文件,如下图所示:

12

  • 标注1:.idea为 Project 的配置文件目录;
  • 标注2:.iml为 Module 的配置文件。

如上图所示,IntelliJ IDEA 的配置文件都存在.idea目录下,以 XML 文件的形式存在,因此咱们也可以通过了解这些 XML 文件来了解 IntelliJ IDEA 的相关配置。至于.iml文件,则为 IntelliJ IDEA 为每个 Module 自动生成的配置文件,一般情况下,咱们是不需要动她的,就让她做一个安静的女神吧!

此外,IntelliJ IDEA 是一个没有 Ctrl + S 的 IDE,因此每次修改完代码之后,咱们只管运行或者调试即可,无需担心保存或者丢失代码的问题。


———— ☆☆☆ ——Back-  >The easiest IntelliJ IDEA tutorial in history<- Contents——  ☆☆☆ ————

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325810250&siteId=291194637