This workshop takes you through a demonstration of the WebSphere Studio Application Developer version 5.0 (hereafter called Application Developer) Core IDE. It focuses on the features in which a Java developer would be interested. The sample application is a simple on-line banking application represented by the Account project. We can withdraw funds from this account. This project has two packages called com.ibm.demo.account and com.ibm.demo.account.testcases.
Note: This workshop requires that
the following products are installed:
|
___ 1. Import files for the Account project
a. If not already started, start Application Developer.
b. Open a Java Perspective by clicking on the Open Perspective button
![]()
and selecting Java.
![]()
c. Create a new Java project by selecting File->New->Project. In the New Project wizard, choose Java from the left-hand pane and Java Project from the right-hand pane.
Click the Next> button.
d. In the Create a new Java project dialogue, specify a Project name of Account.
![]()
Click Finish to create the Account Java project.
e. From the Package Explorer view in the Java Perspective, make sure Account is selected and click mouse-button 2. Select Import....
![]()
f. From the Import selection dialog, select File system. Click the Next> button.
g. From the Import file system selection dialog, click the Browse... button. Navigate to and select the x:\WS50STEW\hands-on\CoreIDE\Account directory. Click Select All.
![]()
Click the Finish button. Note that you will see a number of errors on the Tasks list. That is ok!
h. From the Package Explorer view in the Java Perspective, make sure Account is selected and click mouse-button 2. Select Properties.
i. In the Properties for Account dialog, select Java Build Path in the left-hand pane and the Libraries tab on the right -hand pane.
![]()
j. Click Add External JARs.... Browse to and select <APPDEV_ROOT>\eclipse\plugins\org.junit_3.7.0\junit.jar. Note that <APPDEV_ROOT> is the directory where you installed Application Developer, such as D:\AppDevBeta.
![]()
Click OK. This should remove the compilation errors.
k. If Application Developer is installed in D:\AppDevBeta, continue to 2. Configure the Workbench properties . If Application Developer is not installed in D:\AppDevBeta, continue with this step.
From the Package Explorer view in the Java Perspective, expand the Account project and look for build.xml. Double-click on build.xml to open it in the XML editor. Click on the Source tab to display the source view for this file. Locate the line:
classpath="d:\AppDevBeta\eclipse\plugins\org.junit_3.7.0\junit.jar"/>Change the "d:\AppDevBeta "to the appropriate value for your installation.
___ 2. Configure the Workbench properties
a. This section will prepare the Workbench for various portions of the demonstration. First setup the Workbench to use the J2EE 1.4 SDK.
From the Workbench, select Window->Preferences. Select Java->Classpath Variables from the left -hand pane to display the Classpath Variables. Click New....
![]()
b. In the New Variable Entry dialog, enter JRE_14_LIB for the variable name and x:\JDKs\j2sdk1.4.0\jre\lib\rt.jar for the variable path. Click OK.
![]()
c. With the Workbench Preferences dialog still open, select Java->Installed JREs from the left -hand pane to display the Installed JREs. Click Add....
![]()
d. In the Add JRE dialog, enter JDK 1.4 for the JRE name. Click the Browse... button for the JRE home directory and browse to and select x:\JDKs\j2sdk1.4.0 . Click the Browse... button for the Javadoc URL: and browse to and select x:\JDKs\j2sdk1.4.0 (note that this is the place where src.jar is located for the JDK).
![]()
Click OK.
e. Click OK to dismiss the Workbench Preferences dialog. Answer Yes to any questions about a full rebuild.
___ 1. Explore the Java editor
a. If you are not already in a Java Perspective, open one by clicking the Open Perspective button and selecting Java. Note the Java Perspective, like all Perspectives, provides a customizable view to the components they are working on.___ 2. Explore the Type Hierarchy
b. Expand and explore the com.ibm.demo.account and com.ibm.demo.account.testcases packages.
c. Double-click CheckingAccount.java to open it in the Java editor.
![]()
d. Note the following:
- Expandable structural view of the class in both the Package Explorer and Outline view
- Visual clues such as green, yellow and red symbols to denote public, protected or private methods or variables in both the Package Explorer and Outline view
- Clicking on a method, variable or on import declarations in the Outline view or Package Explorer brings you to that point in the editor
- import declarations shows what is being imported
![]()
a. In the Outline view of the Java Perspective, select the CheckingAccount class. Click mouse-button 2 and select Open Type Hierarchy.___ 3. Explore the Build Path
![]()
b. The Package Explorer view is replaced by a Hierarchy view. Note the following:
- The Hierarchy view shows an inheritance hierarchy
- CheckingAccount extending Account and Account extending Object
- Selecting a class in the hierarchy displays the methods and variable for that class
- Various filters are available to show or hide:
- Inherited methods
- Fields
- Static members
![]()
a. Switch back to the Package Explorer view by clicking on the Package Explorer tab.
![]()
b. Select the Account project, click mouse-button 2 and select Properties to display the properties of the Account project.
c. Select Java Build Path in the left-hand pane to display the properties of the Java build path for the Account project. The Order and Export tab is displayed. Click on the Libraries tab. Note that if we need to add external JAR files we would click on the Add External JARs ... button. We have two JARs configured in the build path, the JRE_LIB - D:\AppDevBeta\eclipse\plugins\org.junit_3.7.0\ junit.jar file and the JRE_LIB - D:\AppDevBeta\eclipse\jre\lib\rt.jar file for JDK 1.3.
Note: The Add JARs... button will add JAR files that exist in the workspace to the build path for this project. The Add External Jars... button will add JARs files that do not exist in the workspace to the build path for this project.
![]()
Click the Cancel button to dismiss the Properties dialog.
d. Note the following about the Package Explorer view:
- junit.jar and rt.jar also appear in the Package Explorer view
- junit.jar and rt.jar can both be expanded like any other JAR
- These referenced JARs can be filtered out by selecting Filters... and selecting Hide referenced libraries
![]()
a. In the Package Explorer view of the Java Perspective, double-click on MyTestClient.java (in the com.ibm.demo.account.testcases to open it in the Java editor. In order to switch between the two different open classes (CheckingAccount.java and MyTestClient.java) simply select the appropriate title tab.___ 2. Working with Javadoc
![]()
Double-click on the title tab for MyTestClient.java to cause the Java editor to fill the entire Workbench view.
b. Examine the code for MyTestClient.java. Briefly, it:
Double-click on the title tab for MyTestClient.java again to restore the Java editor to it's default state. Close CheckingAccount.java by clicking on the X in the title tab for CheckingAccount.java.
- Instantiates a new CheckingAccount object with a value of 100.00
- Calls various methods within the CheckingAccount class
- The withdraw method subtracts the passed amount from the account
![]()
a. In MyTestClient.java, move your cursor over the BigDecimal constructor to display the Javadoc for BigDecimal.___ 3. Working with Code Assist and Templates
![]()
Do the same for System.
Note that if there are methods or objects without Javadoc, all that will be displayed will be the method signature. Verify this by moving your cursor over the withdraw method.
![]()
This can be turned on or off by clicking the Show Text Hover button.
![]()
b. You can look at the Javadoc for a class by selecting the class and clicking Navigate->Open External Javadoc. The keyboard shortcut for this is Shift+F2 .
![]()
From the Outline view, select MyTestClient. From the Workbench menu, click Navigate->Open External Javadoc. You will see the following message:
![]()
This is because we have not configured the location for the Javadoc nor have we generated the Javadoc.
c. First, verify the location of the Javadoc command. From the Workbench menu, click Window->Preferences. Expand Java on the left-hand pane and select Javadoc. Click the Browse... button and browse to and select <APPDEV_ROOT>\runtimes\aes_v4\java\bin\javadoc.exe.
Note that <APPDEV_ROOT> is the directory where you installed Application Developer, such as D:\AppDevBeta.
![]()
Click the OK button.
d. Now create the Javadoc for the Account project. In the Package Explorer view, select the Account project. Click mouse-button 2 and select Export....
e. In the Export Select dialog, select Javadoc. Click Next>.
f. In the Generate Javadoc dialog, ensure that Account is selected. Click Finish to generate the Javadoc for the Account project.
On the pop-up message asking if you want to update the Javadoc location, click Yes.
Ensure that the console displays messages indicating that Javadoc is being generated. If you are on a slower machine, it may take a few seconds.
![]()
NOTE: If the console does not display any messages, from the Workbench menu click Window->Show View->Debug. In the Debug view, select the Javadoc Generation process.
![]()
The click the Console tab to display the console.
g. Now display the Javadoc for the MyTestClient. Select MyTestClient. From the Workbench menu, click Navigate->Open External Javadoc. You should see the Javadoc displayed for MyTestClient.
![]()
h. Close the Javadoc window.
a. In the Java editor for MyTestClient.java, add a new line after the try { line.___ 4. Adding Getters and Setters
![]()
b. Type System.out. and press Ctrl+Space Bar to activate Code Assist. Code Assist is also activated after a configurable period of time. Code Assist displays a list of available methods or objects based on where the cursor is in the source editor. It also displays the Javadoc for that method or object.
![]()
Finish the line of code so it appears as follows and add another blank line after it.:System.out.println("Hello");c. Code Assist also works with Java language elements. Type if and press Ctrl+Space Bar to activate Code Assist and display various if statement templates as well as potential class name matches. A template is a convenience for the programmer to quickly insert often reoccurring source code patterns.
![]()
d. Select the ifelse statement template choice. Note that the template fills in multiple lines and contains hints for what type of language construct is needed.
![]()
Remove the if statement you just added by pressing Ctrl-Z twice.
f. Define a new template for System.out.println(); by clicking on Window->Preferences from the Workbench menu bar. In the left-hand pane, expand Java and select Templates. This is a list of all the Templates defined in the Workbench.
![]()
Click the New... button.
g. In the New Template dialog, enter sop for Name: and System.out.println for the Description.
Enter System.out.println(); for pattern and with the cursor between the parenthesis, click the Insert Variable... button. Double click cursor.
![]()
You should see:
![]()
Click OK to save the sop template. Click OK to dismiss the Preferences dialog.
h. In the Java editor for MyTestClient.java, put the cursor in the blank line after System.out.println("Hello"); .
Type sop and press Ctrl+Space Bar. You should see Content Assist fill in the line with System.out.println(); and position your cursor between the parenthesis.
a. In the Java editor for MyTestClient.java , add a blank line after the Class declaration, that is after:___ 5. Running methods with errorspublic class MyTestClientb. Add a new variable by typing:
private int i;Note the Outline view is updated with the variable when you complete the statement.
![]()
c. Generate getters and setters for the variable i that was just added by selecting i in the Outline view, clicking mouse button 2 and selecting Generate Getter and Setter....
![]()
d. On the Generate Getter and Setter dialog click OK to create the getter and setter methods.
![]()
a. In the Java editor for MyTestClient.java, move the cursor to a blank line right after the main method and just before the comments for the getI method.___ 6. Adding try/catch blocks
![]()
b. Add a new method by typing:
public void errorMethod()Note the this is an invalid line of code. That is ok!!!
{
System.out.printlx();
}
c. Save and compile this class by press the Ctrl+S key. Note that an error will show up in the Task list because of this bad line of code. You can also move your mouse pointer over the red x in the Task list or in the Java editor (where the red x might be hidden by a lightbulb) to display Hover help about the error.
![]()
d. In other Java IDEs, the MyTestClient class could not be executed because it has errors. In Application Developer, we can run this class as long as we do not try to execute the method in error. The main method does not call errorMethod, so we can execute this class. Click on the Run button.
![]()
e. On the Launch Configurations dialog, ensure Java Application is selected and click the New button.
f. On the Launch Configurations dialog, ensure MyTestClient is selected on the left-hand pane and click Run.
You should see the output from MyTestClient in the console.
![]()
a. In the Java editor, remove the try/catch block from MyTestClient by removing:___ 7. Using Quick Fixes
try {and} catch(InsufficientFundsException e) {b. Save and compile this class by pressing the Ctrl+S key. Note that errors appear in the Task list because MyTestClient no longer handles the InsufficientFundsException exception.
System.out.println("Insufficient Funds Exception");
}
c. Highlight the code formerly surrounded by the try/catch block by putting the cursor at the start of the System.out.println("Hello"); statement, pressing and holding the Shift key and moving the cursor by using the down arrow key until the cursor is on the System.out.println("Withdrawing 100"); statement.
![]()
d. Press mouse button 2 and select Source->Surround with try/catch block.
![]()
Note that the code is surrounded by a try/catch block and catches the appropriate exception.
e. In the catch block between { and } enter the following highlighted code (remember to use the sop template!)
System.out.println("Insufficient Funds Exception thrown");![]()
f. Save and compile this class by pressing the Ctrl+S key. Note that errors related to the InsufficientFundsException exception no longer appear.
a. Quick Fixes provide suggestions as to how to fix compile errors. In the Java editor, find the red box on the right hand side of the scroll bar (indicating a compile error) and press the box to move the editor to that line and error.Congratulations, you've completed Part I, "Introduction to the Workbench for the Java Programmer" of the Core IDE lab and are ready to go to Part II, "Debugging Java applications"!
![]()
b. Note the lightbulb icon to the left of the line in error. This means a Quick Fix is available. With the error highlighted, press Ctrl+1 (the number one) to activate Quick Fix. Note that a suggested fix is presented. Choose this fix by double-clicking on it.
![]()
The change is made in the source code.
c. Save and compile this class by pressing the Ctrl+S key. Note that the error related to the System.out.printlx problem no longer appears.
d. Quick Fixes can also be used to quickly create a method. In the Java editor, add a new line below the just corrected System.out.println();. Enter the following line of code:
trace();and press the Ctrl+S key. Note that a compile error relating to this undefined method trace is displayed.
e. With the error selected in the Java editor, press Ctrl+1 (the number one) OR click Edit->Quick Fix from the Menu bar. Either way, Quick Fix displays a suggested fix of creating the trace() method. Chose this fix by double-clicking on it. A new method called trace() is created.
f. Save and compile this class by pressing the Ctrl+S key. Note that the error related to the missing trace() method no longer appears.