In this exercise, you are going to build a simple Hello ...

braintreesmileSoftware and s/w Development

Aug 15, 2012 (5 years ago)

328 views

In this exercise, you are going to build a simple Hello application using NetBeans IDE.

1.

Start NetBeand IDE

2.

Create a NetBeans project

3.

Build and run the program


(1.1) Start NetBeans IDE

1. Doubl
e
-
click NetBeans IDE Icon on the desktop to start the NetBeans IDE. Observe the NetBeans
IDE gets started.


(Figure
-
2.10 below)


Figure
-
2.10: NetBeans IDE













































































(1.2) Create a NetBeans project

1. Select
File
from top
-
level menu and select
New Project

or pre
ss
Ctrl+Shift+N
.


(Figure
-
2.20
below)




Figure
-
2.20: Create New Project

2. Observe that the
New Project

dialo
g box appears.

3. Select
Java
under
Categories
section and
Java Application

under
Projects
section. (Figure
-
2.21
below)

4. Click
Next
.


Figure
-
2.21: Create Java Application project

5. Under
Name and Location

pane, for the
Project Name

field, enter
MyHelloProject
.

6. For the
Create Main Class

field, enter
Hello
.


(Figure
-
2.22 below)


For
Project Location

field,
w
hich indicates the directory in which you are creating a NetBeans project, you can leave it as it is.

7. Click
Finish
.




Figure
-
2.22: Give a project name

8. Observe that the
MyHelloProject
node is created under
Projects
pane of the NetBeans IDE.


9. Modify the IDE generated
Hello.java

as shown in Figure
-
2.23 below.


The code fragment that you
want to add is highlighted in
bold and red
-
colored font
.

public class Hello {




/**



* @param args the command line argu
ments



*/



public static void main(String[] args) {



// TODO code application logic here



System.out.println("This is my first Java program!");



}


}



Figure
-
2.23: Modified Hello.java

10. Introduce a syntax error in the program and observe that NetBeans IDE immediately highlights
the problem as shown in Figure
-
2.24 below.


It detects that

the keyword
void
is misspelled as
voidx
.


Figure
-
2.24: NetBeans IDE detects a syntax error (compile error)

11
. Remove the syntax error.




(1.3) Build and run the program

1. Right click
MyHelloProject
and select
Run
. (F
igure
-
2.30 below)


Figure
-
2.30: Build and run the project

2. Observe that the
Hello.java

is compiled and then
run.


(Figure
-
2.31 below)


Figure
-
2.31: Result of running the MyHelloProject

Summary

In this exercise,


you h
ave built and run Hello Java application using NetBeans IDE.