Introductory Note 613 Using NetBeans Java Integrated ...

kaputmaltwormΛογισμικό & κατασκευή λογ/κού

15 Αυγ 2012 (πριν από 8 χρόνια και 11 μήνες)

340 εμφανίσεις

Cardiff University
School of Computer Science & Informatics
Ysgol Cyfrifiadureg a Gwybodeg
Prifysgol Caerdydd
Introductory Note 613
Using NetBeans Java Integrated Development
Environment on Linux
Robert Evans
2010,2011 Robert Evans.
This Note shows you howto start NetBeans on Linux.We use a simple example
to show the basic process of creating,compiling and running a Java programusing
NetBeans IDE.
1 Using an IDE to Develop Java Programs 1
1.1 Why use an IDE?...............................2
1.2 Running NetBeans..............................2
1.3 Creating a Simple Java Program......................4
1.4 Running the Java Program.........................6
1 Using an IDE to Develop Java Programs
NetBeans is an Integrated Development Environment (IDE) for Java programs.Within
the IDE there are the following:
 a file explorer to give you access to your files;
 an editor to create and amend Java source programs;
 access to the Java compiler and to specialised compilation methods for for par-
ticular Java subsystems;
 a mechanism for running Java programs and applets;
2 Computer Science & Informatics:Introductory Note 613
 a debugger;
 a form editor for creating and editing Java GUI code.
The NetBeans program contains comprehensive on-line help and guidance.
1.1 Why use an IDE?
There’s really not much point in using an IDE if you are building a small Java program.
It’s simpler to use a text editor (e.g.NEdit) to create and amend the Java source,run
javac to compile it and run it with java.
However,if you are developing a larger Java project,an IDE can be useful in or-
ganising your Java source modules,compiling and linking the modules together,and
running and debugging the program – all in an integrated environment.
NetBeans has templates for different types of Java programs.You choose a template
when you use NetBeans to create a Java source.NetBeans will use the template to
start the file for you.
1.2 Running NetBeans
NetBeans is available on the Ubuntu Linux workstations in the School of Computer
Science & Informatics.
Press the left mouse button
over the Applications menu
and select the Programming
category from the menu.
From the sub-menu choose
Information for Users:Introductory Note 613 3
NetBeans begins and shows
a splash screen while it starts
After some question about
providing anonymous usage
data and registering (which
you can say “No” to),the first
NetBeans screen has a Wel-
come panel with links to news,
tutorials,help,blogs and ex-
amples.Clicking on one of the
links,will open a default Web
browser (e.g.Firefox) to dis-
play the documents.
To show online documents
for Netbeans,choose Online
Docs and Support from the
Help pull-down menu.
4 Computer Science & Informatics:Introductory Note 613
A web page opens in your
web browser.
Detailed documents and
training can be found through
the links on this page.
One option is to use the Net-
Beans IDE Quick Start Guide
to learn how to use NetBeans.
Beware that the Quick Start
Guide may refer to a different
(later) version of NetBeans
(so some things may not be
the same).
The following section shows you how to use Netbeans to create a Java program.
1.3 Creating a Simple Java Program
To begin with,choose New
Project...from the File menu.
Information for Users:Introductory Note 613 5
In the New Project dialogue,
you may choose appropriate
project type.For the sim-
ple Java program,choose
Java from the categories list
and Java Application from the
projects list.Click on the Next
button to continue.
A New Java Application dialog panel appears.
In the dialogue,put a project
name (for example Hello) in
Project Name.The Project
Folder will be updated accord-
By default,Create Main
Class is selected (ticked) and
hello.Main will be automati-
cally created.
With Set as Main Project
selected,the newly created
project will be chosen as the
main project (meaningful only
when you are developing a
large application comprising
multiple projects).
Click on the Finish button
to complete the project cre-
A template (under the package hello) is provided for start up:
To change this template,choose Tools | Templates
and open the template in the editor.
package hello;
@author scmxxx
public class Main {
6 Computer Science & Informatics:Introductory Note 613
@param args the command line arguments
public static void main(String[] args) {
//TODO code application logic here
Java syntax is automatically
highlighted,making it much
easier to read and understand.
To create a simple Java program,add the follow line of code after the line starting with
During the typing process,syntax hints are provided by default.
Choose Save All from the File menu to save all the modified files.
Information for Users:Introductory Note 613 7
The Projects panel shows
the file structures of all the
projects.For this example,
project hello contains a single
package hello which then
contains a single Java source
The Navigator panel shows
the classes and members
within the current item.Here
the contains a
single class Main which
then has a member method
main(String[] args).
You can use these panels
to locate quickly different
classes and their members
if you are editing a large
1.4 Running the Java Program
By default,you don’t need explicitly to compile (or build) the project before you run it.
Of course,internally,the Java program needs to be compiled before it is ready to run.
The NetBeans IDE takes care of this process.Simply choosing Run Main Project from
the Run menu will run the program (after building if necessary).
The program output will ap-
pear in the Output panel.