The JDK
The JDK
A Checklist
Creating Your First Application
o Create an IDE Project
o Add JDK 6 to the Platform List
(if necessary)
o Add Code to the Generated
Source File
o Compile the Source File
o Run the Program
Continuing the Tutorial with the
NetBeans IDE
A Checklist
NetB
eans
IDE,
New
Proje
ct
wizar
d,
Nam
e
and
Loca
tion
page
.
5. Click Finish.
The project is created and opened in the IDE. You should see the following
components:
I
D
E
w
i
t
h
t
h
e
H
e
l
l
o
W
o
r
l
d
A
p
p
p
r
o
j
e
c
t
o
p
e
n
.
It may be necessary to add JDK 6 to the IDE's list of available platforms. To do this,
choose Tools | Java Platform Manager as shown in the following figure:
Selecting
the Java
Platform
Manager
from the
Tools Menu
If you don't see JDK 6 (which might appear as 1.6 or 1.6.0) in the list of installed
platforms, click "Add Platform", navigate to your JDK 6 install directory, and click
"Finish". You should now see this newly added platform:
The Java
Platform
Manager
To set this JDK as the default for all projects, you can run the IDE with the --
jdkhome switch on the command line, or by entering the path to the JDK in
thenetbeans_j2sdkhome property of
your INSTALLATION_DIRECTORY/etc/netbeans.conf file.
To specify this JDK for the current project only, select Hello World App in the
Projects pane, choose File | "Hello World App" Properties, click on Libraries, then
select JDK 6 under the Java Platform pulldown menu. You should see a screen similar
to the following:
The IDE is now configured for JDK 6.
When you created this project, you left the Create Main Class checkbox selected in
the New Project wizard. The IDE has therefore created a skeleton class for you. You
can add the "Hello World!" message to the skeleton code by replacing the line:
// TODO code application logic here
HelloWorldApp helloworldapp
package helloworldapp;
/**
* The HelloWorldApp class implements an application that
* simply prints "Hello World!" to standard output.
*/
public class HelloWorldApp {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
System.out.println("Hello World!"); // Display the string.
}
}
Compile the Source File into a .class File
To compile your source file, choose Build | Build Main Project from the IDE's main
menu.
The Output window opens and displays output similar to what you see in the
following figure:
Output
window
showing
results of
building the
HelloWorld
project.
If the build output concludes with the statement BUILD FAILED, you probably have a
syntax error in your code. Errors are reported in the Output window as hyper-linked
text. You double-click such a hyper-link to navigate to the source of an error. You can
then fix the error and once again choose Build | Build Main Project.
When you build the project, the bytecode file HelloWorldApp.class is generated. You
can see where the new file is generated by opening the Files window and expanding
the Hello World App/build/classes/helloworldapp node as shown in the following
figure.
Files
window,
showing the
generated .
class file.
Now that you have built the project, you can run your program.
From the IDE's menu bar, choose Run | Run Main Project.
The
program
prints "Hello
World!" to
the Output
window
(along with
other output
from the
build
script).
Congratulations! Your program works!
The next few pages of the tutorial will explain the code in this simple application.
After that, the lessons go deeper into core language features and provide many more
examples. Although the rest of the tutorial does not give specific instructions about
using the NetBeans IDE, you can easily use the IDE to write and run the sample code.
The following are some tips on using the IDE and explanations of some IDE behavior
that you are likely to see:
« Previous • Trail • Next »
Problems with the examples? Try Compiling and Running the Examples: FAQs.
Complaints? Compliments? Suggestions? Give us your feedback.
Your use of this page and all the material on pages under "The Java Tutorials" banner, and all the material on pages under "The Java
Tutorials" banner is subject to the Java SE Tutorial Copyright and License. Additionally, any example code contained in any of these Java
Tutorials pages is licensed under the Code Sample License.
Copyright © 1995,
2010 Oracle and/or
About Oracle | Oracle Technology Network | Terms of Service its affiliates. All
rights reserved.