Getting Started with Intellij Idea (10.5.1)

本文档引导读者通过IntelliJ IDEA创建并编译简单的'Hello World'程序。从新建项目到编写源代码,详细介绍了如何利用这款强大的Java集成开发环境进行高效开发。

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!

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值