Java Reference
In-Depth Information
will live. Open the HelloWorld subnode by clicking its attached plus sign
(
+
) or by double-clicking the node itself.
Within the HelloWorld module is a src directory marked by a folder icon
with small blue dot (and possibly a HelloWorld.iml file, if you didn't
change the default location of your module file; feel free to ignore that
file during this exercise). Right-click the folder to bring up a context
menu, and select
New | Package
from that menu. (Alternatively, you can
begin using
IDEA
's huge library of keyboard shortcuts: Press
Alt+Insert
to open a New context menu.)
3
You're prompted for the name of this new package. Type in the name
com
, and click
OK
(or press
Enter
). Doing so creates the first layer of the
package structure in your project.
4
Repeat the process in steps 3 and 4 to create the subpackage
acme
under
com
,
and then
helloworld
under
acme
.
5
With the
com.acme.helloworld
package created, right-click the
hel-
loworld
package icon and select
New | Class
from the context menu
(
Alt+Insert
).
6
Enter the name
HelloWorld
as the new class name, and click
OK
.
7
IDEA
creates a simple Java source file with the appropriate package and class dec-
larations. It also opens that file in the source code editor. Now that you have the
shell, you can edit the file to suit your needs. Add the
main()
method shown in
listing 1.1, but follow these steps to do so:
Inside the
HelloWorld
class, type the letters
psvm
and then press
Ta b
. The
main()
method should be roughed out for you by
IDEA
's Live Template
mechanism, a customizable code generation facility.
1
Inside the
main()
method, type the letters
sout
, and then press
Ta b
.
Again, the call to
println()
is added for you, and your cursor is placed
within the double quotes, waiting for the
String
you wish to print.
2
Listing 1.1
A simple
HelloWorld
application, written in IDEA
package com.acme.helloworld;
/**
* Created by IntelliJ IDEA.
* User: ssaunders
* Date: 1-Jun-2005
* Time: 9:00:00 AM