This document takes you through the basics of using NetBeans IDE 6.1
by using the HelloWeb Web application you created using NetBeans
IDE 6.1 Quick Guide for Web Application. This document is designed
to get you going as quickly as possible. For more information on
working with NetBeans IDE, see the Support
and Docs page on the NetBeans website.
Expected duration: 60 minutes
Before you begin, you need to install the following software on your computer:
In this exercise, you are going to build "HelloWeb" sample application that comes with the hands-on lab zip file.
0. Start NetBeans IDE.
1. Open HelloWeb
NetBeans project.
2 Build and run HelloWeb project.


In this exercise, you are going to
explore various editing features of NetBeans IDE 6.1.
1. Open NameHandler.java under
HelloWeb->Source
Packages->org.me.hello.
2. Select name string and
right-click it. Select Refactor
and then Rename.

3. In the Rename Field name
dialog box, type username in
the New Name field. Click Next.

4. Observe the result of refactoring of renaming.

5. Right-click HelloWeb project node and select Run. Observe that the
application behaves the same.
1. Open NameHandler.java.
2. Create some compile errors in various places of the
code and see Error stripes are displayed in the right side of the
editor. In the example below, a random string, x, is
entered in various places to generate compile errors for the sake of
this exercise.

3. Click CTRL-Z (Undo) several
times until above compile errors are gone.
1. Select Tools from the menu bar.
2. Select Options. The Options dialog box appears.

3. Select Editor
4. Select Code_Templates tab
window.

5. Click New.

6. In the New Code Template Dialog box, type stringx for the Abbreviation field. Click OK.

7. In the Expanded Text: textarea, type
in String
x; //This is my test
code abbreviation. Click OK.

8. In the NameHandler.java, type stringx and press Tab. You should
see the expanded code.

9. In the NameHandler.java
code, type trycatch and
press Tab key and see
it gets expanded
as well.


10. Undo
it by pressing
CTRL+Z.
1. In the NameHandller.java code, type
ISR and press CTRL-SPACE. You should see the
two Java APIs that
starts with the I, S, and R as starting capital letters.

2. Undo the changes by pressing CTRL+Z.
1. Open response.jsp
under HelloWeb->Web Pages.
2. In any place of the file, type <jsp.
You will see
code completion screens being popped up. You can also induce code
completion by pressing CTRL-SPACE.

3. Undo the changes by pressing CTRL-Z.
In this exercise, you exercises a few
code editing features of NetBeans IDE 6.1.
In this exercise, you will exercise the
following code navigation
features of NetBeans IDE 6.1.
1. Select Navigate from the menu bar and then select Go to Type (Ctrl+O). The Go to Type dialog box appears.

2. Type NameH and see all
the
classes whose name starts with NameH.
3. Click Open. Observe NameHandler.java code displayed in
the editor window.

1. Right-click in any point of NameHandler.java code and
choose Select in and Files.

2. Observe that the the Files view gets displayed.

3. Right-click in any point of NameHandler.java
code and choose Select in
and Favorites to see the file
under Favorites tab window.
4. Right-click in any point of NameHandler.java
code and choose Select in
and Projects.
1. In the NameHandler.java
code, move the cursor to String while
holding down the CTRL
key. The String string
will turns into a hyperlink.

2. Click the String string.
You will see the source code of the String
class.
3. Try the same for Serializable. You should see the source code
of the java.io.Serializable interface.



In this exercise, you will exercise the
following features of NetBeans IDE 6.1.
0. Make sure HelloWeb project
is the Main project. (A project node in bold font is the Main
project.) If it is not, right click HelloWeb and select Set Main Project.
1. Open response.jsp in the
editor window.
2. To make a breakpoint on the <jsp:setProperty
name="mybean"
property="*" /> line, move your cursor to the location of the
gray
colored vertical bar of the line and click. The dark pink
colored bar indicates that the breakpoint is created.

3. Right click HelloWeb project
node and select Debug.
NetBeans will rebuild and deploy the application
for
debugging.

4. When the browser prompts you to enter your name, enter a name and
click OK button.

5. Note that the breakpoint is hit.
6. Click Local Variables tab
window. Expand mybean and
notice that the username field
has not been set -
it is null.

7. Press F8 to step
over. Note that the username field
of the mybean has been
changed to the name you entered, Sang
Shin, in this example.

8. Change the name to someone else, like, "James Gosling" and
press Enter.

8. Press F5 to continue.
(You can also select Run from
the menu
bar and then select Continue.)
9. Observe the new name is displayed in the browser.

Now you are ready to unit test the methods of NameHandler.java using built-in JUnit. For the sake of this exercise, you are going to add another method called addNumbers(int x, int y) to the NameHandler.java and test if the method performs as expected.
1. Add addNumbers(...)
method
as shown below to the NameHandler.java. after setName(..) method.
| public int addNumbers (int x,
int y){ return (x+y); } |
2. Click Save All.

2. Right click NameHandler.javanode.
Select Tools->JUnit
Tests->Create JUnit Tests.

3. The Create Tests dialog box appears. Accept all default values
and click OK.

4. Observe that NameHandlerTest.java
code gets displayed in the
editor window. Also observe that NameHandlerTest.java
is created
under Test Packages.

5. Comment out the IDE generated fail()
methods in testGetName(),
testSetName(), and testAddNumbers() methods.
6. Change the testAddNumbers() method as following. The code
fragments that need to be modified are high-lighted in red color.
| /** * Test of addNumbers method, of class NameHandler. */ public void testAddNumbers() { System.out.println("addNumbers"); int x = 5; int y = 7; NameHandler instance = new NameHandler(); int expResult = 12; int result = instance.addNumbers(x, y); assertEquals(expResult, result); // TODO review the generated test code and remove the default call to fail. //fail("The test case is a prototype."); } |

7. Select Run from the menu bar and then select Test "HelloWeb".

8. Observe that testGetName()
failed while testSetName() and
testAddNumbers()
succeeded.
9. Double-click testGetName Failed
(0.016s).

10. Comment out the assertEquals(expResult,
result); method

11. Select Run from the
menu bar and then select Test
"HelloWeb".
12. Observe all tests succeeded.
1. If HTTP monitoring window does not get displayed, select Window from menu bar and then select HTTP Monitor.
2. Run the above application.
3. Observe the captured HTTP traffic under HTTP Monitor
window.
Trouble-shooting: If the
HTTP Monitor window shows no records you have to turn on the HTTP
Monitoring for this server. Go to the Runtime tab, expand the
servers list, right click on the server name and select Properties.
Check Enable HTTP Monitor, close the dialog and restart the server
(right click on the server name and select restart).

4. Click other tab windows such as Cookies, Session, Context,
Client and Server, and Headers to see more information
about a HTTP
request or response.
5. You can do replay or Edit and Replay.
Note: If you are running NetBeans 5.0 or 5.5, you
will find that when you select
"Edit and Replay" for one of the records in the HTTP Monitor, you can
edit the parameter value but when you send the HTTP Request the change
is ignored and the old value is sent instead. There is now a bug open
for this issue. Hopefully it will be fixed for
the final 5.5 release:
http://www.netbeans.org/issues/show_bug.cgi?id=73655

In this exercise, you exercised source level JSP page debugging first. You also learned how to do JUnit testing and how to capture HTTP traffic.
In this exercise, you will do various
project management such as
following:
1. Right click HelloWeb project
and select Copy Project.

2. In the Copy Project
dialog box, type in a new project name, HelloWebClone, in this example.
Click Copy button.

3. Note that HelloWebClone project gets created.
4. Right click HelloWebClone project and Run.
1. Right click HelloWebClone project
and select Rename Project.
2. In the Rename Project dialog box, give it a new name, HelloWebClone2, and click Rename.
3. Observe that the project name has been changed.
1. Right click HelloWebClone2 project
and select Delete Project.
2. In the Delete Project
dialog box, select Also Delete Source
Under ... if you want to delete source code as well.

1. Go to the directory you have your HelloWeb project's build.xml
file. If you take the default, it should be the
<home-directory>/HelloWeb.
2. Type ant and observes
that
it gets built correctly
In this exercise, you exercised source level JSP page debugging. You also learned how to capture HTTP traffic.
| // This
is another method I added to the NameHandler.java for JUnit testing public int compareTwoNamesIgnoringCase(String name1, String name2){ return name1.compareToIgnoreCase(name2); } |