Hello World: The Application in NetBeans 4

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

5 Ιουν 2012 (πριν από 5 χρόνια και 18 μέρες)

342 εμφανίσεις

Hello World: The Application

in NetBeans 4.1


Charlie Martínez

UMUC Asia

Page
1

of
14

If the NetBeans 4.1 application along with the Java 5 is installed on your computer,
then the NetBeans 4.1 icon should appear on the computer desktop.

Start the
NetBeans 4.1 IDE application by double clicking the NetBeans 4.1 icon on your
desktop.
If you

do not maintain the icon on your computer desk top you should be
able to launch

(run) the NetBeans 4.1 IDE from the

Windows

Start
-
> Programs
-
>
NetBeans 4.1.

This document contains one of the simpler ways that a programmer can create a
new programming p
roject using NetBeans and Java.


NetBeans Icon on Desk Top






The NetBeans Icon


Hello World: The Application

in NetBeans 4.1


Charlie Martínez

UMUC Asia

Page
2

of
14

Let’s begin by Opening a New Project area where we can create a Java application in
NetBeans.

Select
F
ile
-
> Open Project


Open

Project










Open Project


Hello World: The Application

in NetBeans 4.1


Charlie Martínez

UMUC Asia

Page
3

of
14

This window should pop
-
up. This is how

we tell NetBeans what we plan to do.

For now, insure that
:

1.

In the
C
a
tegories

window, the folder ‘
General
’ is highlighted.

2.

In the
P
rojects

window, ‘
Java Application’

is highlighted.

3.

Finally, single click the ‘
Next >’

button



What type of Project?






1.) G
eneral


2.) Java Application


3.) Next >


Hello World: The Application

in NetBeans 4.1


Charlie Martínez

UMUC Asia

Page
4

of
14

The next window dialog

to pop
-
up request
s

some information from you.

1.

The ‘
Project Name’
:

Enter the name of this project “HelloWorldAgain”

a.

Use the provided ‘
Project Location’

and
‘Project Folder’

for now.

2.

Insure that the two check boxes, labeled
‘Se
t as
M
ain Project’

and

C
reate Main
Class’

have a check mark.

3.

Finally, click the
F
inish

button.



Give the Project a name.







1.) Project Name


2
.) The Check

Boxes


3.)
F
inish


Hello World: The Application

in NetBeans 4.1


Charlie Martínez

UMUC Asia

Page
5

of
14


The
HelloWorldAgain

project should now be

displayed in the
Project

window and
Main.java

opens in the
Source

editor.

No
tice the source code file already has some of the preliminary work done for you.

This is the window that has the tab
Main.java.

Take some time to review the contents of the windows so you learn what to expect
when you create your own applications.

NetBeans

tries to help you out by providing a common template when the .java file
is opened for the first time. Look thru what is given to you by NetBeans as there are
additional lines of code
, required by NetBeans,

that are not presented in the
textbook.



NetBeans Auto Gen

TODO… line of
source code.


This is the Java
source code window


This is the Project
window


Hello World: The Application

in NetBeans 4.1


Charlie Martínez

UMUC Asia

Page
6

of
14


W
here you see this line of comment
// TODO code application logic here

replace it with…
System.out.println(“Hello World Again”);


Notice the IDE(Integrated Development Area) tries to help you by including both
sets of
double quotes




for you.

Be careful that you get only one set of double quotes.


Did you include the ‘;’ semicolons?

Do you still have all of the ‘{“open and ‘}’close braces?

There should be four of them.

Does every open
parenthesis

have
matching close parentheses
?


Type in 'Hello World Again'


Hello
World

Again

Hello World: The Application

in NetBeans 4.1


Charlie Martínez

UMUC Asia

Page
7

of
14

The next step is to ‘compile’ your program.
One way to compile a program with
NetBeans is to
Single click the ‘
Build Main Project’

icon on the menu bar.

If you have errors, the NetBeans IDE tries to help you out some. T
he error listing is
in the bottom window

labeled
Output


Helloworldagain(jar)
.


Build Main Project.






Build
Main
Project

Report
from the
compile
,
if exist.


Hello World: The Application

in NetBeans 4.1


Charlie Martínez

UMUC Asia

Page
8

of
14


Now
let’s

see if the Java program works. Click the ‘
Run Main Project’

icon on the
menu bar.


Execute the Application







Run
Main
Project

Hello World: The Application

in NetBeans 4.1


Charlie Martínez

UMUC Asia

Page
9

of
14



To see the outpu
t of this Java program, look in the bottom window again.


The Results







Results

Hello World: The Application

in NetBeans 4.1


Charlie Martínez

UMUC Asia

Page
10

of
14



The NetBeans application does several other things for yo
u behind the scenes while
you w
ere working on the source code.

Look over in the

Projects window and browse through

the

v
arious files that w
ere
created.


Various Types of Files Created





The Projects Window.


Hello World: The Application

in NetBeans 4.1


Charlie Martínez

UMUC Asia

Page
11

of
14



Once
you’re

done,


1.

c
lose

the project
: from the main menu select
F
ile
-
> Close “HellowWorldAgain”


2.

e
xit
NetBeans
selecting
F
ile
-
>
E
xit
.


Close the Project
1









2.) Exit

1.) Close “HelloWorldAgain”

Hello World: The Application

in NetBeans 4.1


Charlie Martínez

UMUC Asia

Page
12

of
14





To re
-
open a Project
,

follow th
e menu to your project and navigate
File
-
> Open
Recent Project
-
> Project Name
.




Open a Previous Project











To open a
project that
has been
closed.

Hello World: The Application

in NetBeans 4.1


Charlie Martínez

UMUC Asia

Page
13

of
14





A file view of the Java
source

and
class

that were created using Win
dows
Explore.


Windows Explore View
1


Windows Explore View 2


Hello World: The Application

in NetBeans 4.1


Charlie Martínez

UMUC Asia

Page
14

of
14


Windows Explore View 3