Getting Started with Intellij Idea (10.5.1)

简介: This document guides you through the process of writing and compiling a 'Hello World' type program using Intellij Idea.

This document guides you through the process of writing and compiling a 'Hello World' type program using Intellij Idea.

First of all, find Intellij Idea on the desktop or start menu (look for IntelliJ IDEA under All Programs) and open the application - it may take a few seconds to start up. 

Select the File-New Project option, and you'll be presented a dialogue similar to the following. This will give you the choice to create a new project from scratch or from an existing source code/model. For this tutorial choose "create project from scratch". 

 

 

Next you need to choose a project name and the new folder you've just created. The same dialogue can be used to create different types of projects. For now select "Java Module" for a standard J2SE project.

 

 

Then click Next, to be presented with another dialogue, which will enable you to create a source folder (usually called src). You always have the option not to create such a folder but it is highly recommended to do so.
 

 

 

Next you will have the choice of including some advanced technologies into your project. Do not select any of the listed technologies as we are going to write a simple java project

 

 

 

Select finish and the project will load into the IDE.

Creating a Package

Select the Project view on the left Pane, and right click the 'test' module.  From the pop-up menu select 'new package' as shown below:

 

 

 

Now enter the name 'Test' for the package name:

 

 

And click Ok.

Now right click on "Test" to create a new class:

 

 

 

 

Enter the name 'HelloWorld'.

You should now see something like this in the code view:

 

 

 

The next step is to write the code.

Note that Intellij will format the code for you.  It does this as you type, but sometimes you'll need to manually invoke a 'reformat' - do this with <ctrl>+<alt>+L

To create the main method, you can use a built-in shortcut sequence: type psvm<tab> within the class definition, and you'll get this:

 

 

 

Now enter the single line at the cursor: System.out.println("Hello world!");  (you can do same of this with the shortcut sout<tab>).

Observe in the screen shot above the "yellow light" alongside the top right corner of the code window. This indicates that the code is ready to compile but there are some warnings, this light will turn into green when there are no warnings (can you figure out what is the warning).  Experiment with corrupting the code, and note the red light and the red line(s) that appear with appropriate error messages.

Make sure you've corrected any corruptions and then compile the code using the "Make Project" option from the Build menu or "Compile HelloWorld.java" option from the same menu, or the keyboard shortcut <ctrl><shift><F9>.

In order to run the program, right click on "Hello" class and select "run HelloWorld.main()".

 

Now, for next runs simply click the green triangle at the top of the window to run the program (if it isn't green the program is not runnable so check that you haven't missed any steps earlier!).

The output of the program should look something like the following:

 

 

 

Exercise

Study the directory structure of the project.  What do you notice about the location of each file that has been created?

Concluding Remarks

You may think right now that this was a fairly long-winded process to write a hello-world program, and that you could have done it quicker using TextPad!

That may be true for a Hello World program, but as the code you write becomes more complex, and exploits more of the Java API, a good IDE such as Intellij Idea is indispensible.

Learn to use it effectively and you will not regret it!

 

 

 

 

 

目录
相关文章
|
2月前
|
IDE Java 开发工具
如何安装intellij IDEA
如何安装intellij IDEA
|
4月前
|
SQL Java 数据库连接
IntelliJ IDEA相关配置(二)
IntelliJ IDEA相关配置(二)
|
4月前
|
IDE Java 开发工具
IntelliJ IDEA相关配置(一)
IntelliJ IDEA相关配置(一)
|
6月前
|
SQL Java Android开发
IntelliJ IDEA 使用总结
IntelliJ IDEA 使用总结
80 0
|
7月前
【IntelliJ IDEA】idea 修改项目名称
【IntelliJ IDEA】idea 修改项目名称
59 0
|
11月前
|
IDE Java Maven
如何安装intellij IDEA(二)
如何安装intellij IDEA(二)
|
11月前
|
开发工具
如何安装intellij IDEA(一)
如何安装intellij IDEA(一)
|
缓存 固态存储 Java
IntelliJ IDEA 的安装、配置与使用
IntelliJ IDEA 的安装、配置与使用
216 0
|
安全 Java 测试技术
IntelliJ IDEA - 使用 IDEA Remote Debug 进行远程调试
IntelliJ IDEA - 使用 IDEA Remote Debug 进行远程调试
657 0
IntelliJ IDEA - 使用 IDEA Remote Debug 进行远程调试
|
Java
IntelliJ IDEA - 报错篇
IntelliJ IDEA - 报错篇
147 0
IntelliJ IDEA - 报错篇