More Related Content
Similar to Part 2 java development
Similar to Part 2 java development (20)
Recently uploaded
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
Part 2 java development
- 1. Rational Application Development certification
prep, Part 2: Java development
Skill Level: Intermediate
Mr. Bobby McChesney (mcchesne@us.ibm.com)
Sr. Learning Specialist
IBM
07 Mar 2006
Prepare for the IBM Certification Test 255, Developing with IBM Rational Application
Developer for WebSphere Software V6. The Rational® Application Developer for
WebSphere® Software Java™ Development tutorial is the second tutorial in a series
of seven tutorials created to help you get ready for the IBM certification test. Learn
how to create Java projects, packages, classes, and methods using the Java
development tools, wizards, and features in the workbench. This tutorial also
introduces the perspectives and views that facilitate your Java development efforts.
Section 1. Before you start
About this series
Rational Application Developer for WebSphere Software is the IBM Software
Development Platform that allows you to quickly design, develop, analyze, test,
profile and deploy Web, Web services, Java, J2EE, and portal applications. This
series of seven tutorials helps you prepare to take the IBM certification Test 255,
Developing with IBM Rational Application Developer for WebSphere Software V6 to
become an IBM Certified Associate Developer. This certification targets entry level
developers and is intended for new adopters of IBM Rational Web Developer or IBM
Rational Application Developer for WebSphere Software V6.0, specifically
professionals and students entering into Web development using IBM products.
About this tutorial
This tutorial is the second in the series designed to help you prepare for the IBM
Java development
© Copyright IBM Corporation 1994, 2007. All rights reserved. Page 1 of 37
- 2. developerWorks® ibm.com/developerWorks
Certification Test 255: Developing with IBM Rational Application Developer for
WebSphere Software V6. It highlights features in the product, but does not replace
the knowledge and familiarity that you obtain from using the product on a regular
basis. The tutorial takes a basic approach to using the Rational Application
Developer for WebSphere Software workbench. It is assumed you have completed
the first part in this series and already know how to navigate the workbench. You
begin by creating a Java project, then populating it with appropriate resources, and
learning the Java editor and development environment. The tutorial focuses on the
Package Explorer, Hierarchy, Outline, Task, and Problems views.
After you complete this tutorial, continue with the third tutorial, which presents an
overview of Web development.
Objectives
After completing this tutorial, you will know how to use the workbench Java editor
and development environment. The tutorial concentrates on the Java perspective
and views that assist in Java development, so you will be familiar with the Java build
path, know how to refactor your code, how to use the Java search function, and how
to use resource and project property menus.
Prerequisites
This tutorial is written for Java developers whose skills and experience are at a
beginning to intermediate level. You should have a general familiarity with using an
integrated development environment.
System requirements
To run the examples in this tutorial, you need to install Rational Application
Developer for WebSphere Software or Rational Web Developer for WebSphere
Software. Download a free trial version of Rational Application Developer for
WebSphere Software if you don't already have a copy of it.
The hardware and software requirements for this software can be located at IBM
Rational Application Developer System Requirements.
Section 2. Getting started
This tutorial assumes you have installed a Rational Software Development-based
workbench and know how to navigate the workbench. The Rational Application
Developer family of products is based on the Eclipse workbench. For the sake of
Java development
Page 2 of 37 © Copyright IBM Corporation 1994, 2007. All rights reserved.
- 3. ibm.com/developerWorks developerWorks®
brevity, the Rational Application Developer for WebSphere Software will be referred
to as Application Developer or as the workbench.
The first thing you are going to do is switch to the Java perspective. If you need a
reminder, this can be done either from the Window main menu bar option, or from
the Open a perspective button. The default views in the Java perspective are the
Package Explorer, Hierarchy, Diagram Navigator, Outline, Problems, Javadoc, and
finally, the Declaration view.
Each perspective has a different set of default toolbars that are included in the
toolbar area located directly below the main menu bar. The Java perspective has,
among others, the New Java Element creation toolbar. This toolbar contains the
New Java Project, New Java Package and New Java Class toolbar icons.
Figure 1. The Java perspective
This tutorial covers the concept of tasks, so go ahead and add the Tasks view to the
Java perspective. Need another reminder? Window > Show View > Tasks. Now
that you have the workbench set up, proceed with the first development task in the
tutorial.
Java development
© Copyright IBM Corporation 1994, 2007. All rights reserved. Page 3 of 37
- 4. developerWorks® ibm.com/developerWorks
Section 3. Creating Java resources
Java projects
There is more than one way to perform most tasks in Application Developer. As you
step through this tutorial, you will perform tasks using different methods so that you
cover most of the bases. First, create a Java project to store the Java code. The File
> New option is always available for development resources, so use this option first.
First, create a package that contains utility code for the main project.
Select File > New > Project from the main menu. Select Java Project from the list
of projects and click Next.
Figure 2. New Java project
Java development
Page 4 of 37 © Copyright IBM Corporation 1994, 2007. All rights reserved.
- 5. ibm.com/developerWorks developerWorks®
Take a look at the New Java Project wizard's options. The options that can be
specified are Project name, Location, and a Project layout. The project name is self
explanatory, but aside from being the name of the new Java project, it is also the
name of a directory created to contain the project resources. Name the new Java
project Utility. The location option lets you either create the Java project inside
the current workspace or specify an arbitrary directory in the file system. The project
layout lets you use the project folder as the root for your source code and compiled
class files or create separate source and output folders.
The New Project wizard allows access to the different types of
projects supported by Application Developer. Some are:
• Dynamic Web Project
• EGL Project
• EJB Project
Java development
© Copyright IBM Corporation 1994, 2007. All rights reserved. Page 5 of 37
- 6. developerWorks® ibm.com/developerWorks
• Portal Project
• Portlet Project
• Portlet Project (JSR 168)
Notice that you can select from folders to access other project
types. Select Show All Wizards for more options.
Figure 3. Java Project wizard
The Configure Defaults button displays the Preferences page where you can specify
build path entries and the source and output folder names. Click Configure
Defaults to explore its options.
The build path is the path used to find classes that are referenced in
the source code. During compilation, this path is used to search for
classes outside of the current project. It also defines the search path
that is used for the Organize Imports feature. This feature is
Java development
Page 6 of 37 © Copyright IBM Corporation 1994, 2007. All rights reserved.
- 7. ibm.com/developerWorks developerWorks®
discussed in more depth later.
The JRE library is already included on the build path.
Figure 4. Configure defaults button
Back in the New Java Project wizard, select Next. The Java Settings page allows
settings to be changed for the project. After exploring them, click Finish.
The Java Settings tabs:
Source
Add source folders to the build path
Projects
Add other Projects to the build path
Libraries
Define JARs and class folders on the build path
Order and Export
Define the Java build path order
Figure 5. Java Settings page
Java development
© Copyright IBM Corporation 1994, 2007. All rights reserved. Page 7 of 37
- 8. developerWorks® ibm.com/developerWorks
There should now be a Utility project in the Package Explorer view. Notice that
the new project folder icon has a letter "J" decorator. This indicates that it is a Java
project. Label decorations are used to show extra information about an item by
modifying its label or icon.
Packages
Now that you have a Utility Java project, add resources to it. The next logical step is
to create a Java package to contain classes inside the Java project. Use the Java
package context menu option to create the package. Right-click the Java package
and select New > Package.
Figure 6. New Java package
Java development
Page 8 of 37 © Copyright IBM Corporation 1994, 2007. All rights reserved.
- 9. ibm.com/developerWorks developerWorks®
Because the New Java Package wizard was initiated from the Utility Java Project's
context menu, Utility is already present in Source Folder. Specify
com.dw.utilities as the package name, and click Finish.
Figure 7. Create a Java package
Java development
© Copyright IBM Corporation 1994, 2007. All rights reserved. Page 9 of 37
- 10. developerWorks® ibm.com/developerWorks
The new com.dw.utilities Java package icon is white indicating an empty package. It
might help to notice that, by default, the JRE System Library is part of every Java
project. This indicates that by default it's on every Java project's build path and you
do not need to modify any Java project settings to use the workbench's default JRE.
Figure 8. Empty package
Classes
You can finally get down to the business of creating a Java class. You are going to
keep this simple to illustrate concepts. Create a class that you can use later for
another project. Use the com.dw.utilities' context menu and select New > Class.
Again, the Source Folder and Package fields will be pre-filled because you used the
package's context menu. Type HelloHelper in the Name entry field.
New Java Class entry fields:
Source Folder
Valid source folder.
Java development
Page 10 of 37 © Copyright IBM Corporation 1994, 2007. All rights reserved.
- 11. ibm.com/developerWorks developerWorks®
Package
Package to contain the new class.
Enclosing type
To create a nested class.
Modifiers
Access modifiers: public, default, private, protected, abstract,
final, and static.
Superclass
New class extends a superclass for inheritance.
Interfaces
New class implements an interface.
Method stubs
Automatically generate a main() method, constructors from the
superclass, or inherited abstract methods.
Figure 9. New Java class
Java development
© Copyright IBM Corporation 1994, 2007. All rights reserved. Page 11 of 37
- 12. developerWorks® ibm.com/developerWorks
Click the Add button in the Interfaces section of the page. Type Ser to search for the
java.io.Serializable interface. Select Serializable in the Matching types panel and
java.io in the Qualifier panel.
Add interfaces window:
Choose interfaces
Text typed here filters through interfaces on the build path.
Matching types
Matching filtered interfaces.
Java development
Page 12 of 37 © Copyright IBM Corporation 1994, 2007. All rights reserved.
- 13. ibm.com/developerWorks developerWorks®
Qualifier
Packages to distinguish duplicate matching interface names.
Figure 10. Implemented interfaces selection
Click OK and then Finish back on the New Java Class page. The Java editor
automatically opens with the new class code preloaded.
Section 4. Java development environment
Java development
© Copyright IBM Corporation 1994, 2007. All rights reserved. Page 13 of 37
- 14. developerWorks® ibm.com/developerWorks
Java editor
The Java editor is now open, so it's time to learn about the default Java development
environment in Application Developer. The development environment used in
Application Developer is inherited from its Eclipse base. The Java development tools
(JDT) are a set of extensions to the workbench that let you edit, compile, and run
Java programs. The JDT provides a number of sophisticated features including
incremental compilation, code snippet evaluation, content assist, type hierarchies,
and hot code replace.
Incremental compilation occurs whenever Java files are saved and is achieved
through the Java builder. Every Java project has the Java builder associated to it by
default. Problems detected during compilation are classified as either warnings or
errors and are displayed in the Problems view. Double-clicking on a problem or
warning in the problems view opens the Java editor to the location where it occurs. A
warning does not prevent a program from executing. Errors are based on the Java
Language Specification. For some types of problems you can specify whether you
want the Java compiler to report them as warnings, errors, or to ignore them. Types
of problems that can be set to be detected as warning, errors, or ignored are Unused
import statements, Unnecessary else statements, Use of deprecated APIs and
Unexternalized Strings. To change the default settings, click Window > Preferences
> Java > Compiler.
Figure 11. Java editor
Notice the grey column on the left margin of the Java editor. It is called the marker
bar and contains icons that flag information to the developer. The icons that can
appear in the marker bar are shown on the left. In this case, the current markers are
task markers associated to TODO tags that are automatically generated from
templates associated with code generation in the Java editor.
To view or modify your existing Java editor templates, click Window > Preferences
Java development
Page 14 of 37 © Copyright IBM Corporation 1994, 2007. All rights reserved.
- 15. ibm.com/developerWorks developerWorks®
> Java > Code Style > Code Templates and Window > Preferences > Java >
Editor > Templates.
Another item of interest is the asterisk that is next to the file name on the Java editor
window's tab. The asterisk is an indicator that the file contains changes that have not
been saved to the file system. To save press Ctrl-S, select File > Save from the
main menu, or click the Save button on the toolbar (looks like a diskette).
The TODO tag is generated by Application Developer to signal that the developer
needs to perform a coding task. The workbench places task markers in the marker
bar wherever TODO tags are located to indicate when the tool generates content the
developer may need to modify or complete. Developers can also manually create
task markers by right-clicking in the marker bar and selecting Add Task. This allows
developers to leave markers for themselves for tasks that still need to be completed.
Manually created task markers have properties that include a descriptive text, a
priority (High, Normal, or Low), and a completion indicator. You can set or read
these properties from the Properties option on the context menu of either the marker
on the marker bar or the Tasks view. You can view all current TODO tags and
manually created tasks in the Tasks view. If you double-click a TODO or a task line
in the Tasks view, it opens the corresponding file on the line where the TODO tag or
task was created.
Figure 12. Tasks
Now create a private String to contain the popular message that is displayed by the
Java program. Type private String text=".
Figure 13. Content Assist
Java development
© Copyright IBM Corporation 1994, 2007. All rights reserved. Page 15 of 37
- 16. developerWorks® ibm.com/developerWorks
When you type the first quotation mark, the Java editor automatically appends the
matching quotation mark that completes the String you are creating! This feature is
part of the Content Assist feature known as Completion inserts. Go ahead and finish
what you were typing, private String text="Hello World!";. The Java
editor can also generate certain source code when you are performing basic coding
techniques. Bring up the editor's context menu (right-click in the editor) and select
Source > Generate Getters and Setters.
Figure 14. Generate Getters and Setters
The Generate Getters and Setters window is prepopulated with the fields in your
Java class. You can now select the methods you want the editor to generate. Select
both of them. Notice that the window also allows you to select the insertion point for
the new methods, the ordering of new methods (grouped by setters and then
getters, or by matching pairs), and then the access modifiers that should be used.
Figure 15. Getters and Setters
Java development
Page 16 of 37 © Copyright IBM Corporation 1994, 2007. All rights reserved.
- 17. ibm.com/developerWorks developerWorks®
You now have a getter and a setter method that meet standard naming conventions
to access the private text field.
Figure 16. Getter and Setter code
Java development
© Copyright IBM Corporation 1994, 2007. All rights reserved. Page 17 of 37
- 18. developerWorks® ibm.com/developerWorks
Clean up the code layout in the file by pressing Ctrl-Shift-F or selecting Source >
Format from the workbench main menu. The code is formatted according to how
you set your specific code formatting preferences. To view or change code
formatting, navigate to Window > Preferences > Java > Code Style > Code
Formatter. The Preview pane shows you a sample of your current preferences.
Figure 17. Code formatter preferences
Java development
Page 18 of 37 © Copyright IBM Corporation 1994, 2007. All rights reserved.
- 19. ibm.com/developerWorks developerWorks®
To change the formatting preferences, click the Show button for the Java
Conventions [built-in] profile above the preview. Notice that you can change many
conventions, including the indentation, the location of code braces, where to insert
blank spaces, whether to delete blank lines in code, if you want to insert new lines
before braces or control statements, the maximum line length, and the layout of
control statements, to name a few.
Figure 18. Changing code formatter
Java development
© Copyright IBM Corporation 1994, 2007. All rights reserved. Page 19 of 37
- 20. developerWorks® ibm.com/developerWorks
Java features and views
Take a moment to notice some features in the workbench. In the Java perspective
you should currently have the Package Explorer view, the Java editor, and the
Outline view to the right (you might have closed views or moved them; if so, they can
be reopened to follow along). In the Package Explorer you see icons for the current
project, package, and class. You also should notice that because you are
programming in Java, you have access to the Java runtime environment's system
library. In the Java editor you may notice some triangles near the marker bar on the
left. These triangles control Code Folding. By clicking on them you can expand or
collapse Java classes, comment sections, method bodies, and even the import
statements at the top of your file.
Figure 19. Workbench features
Java development
Page 20 of 37 © Copyright IBM Corporation 1994, 2007. All rights reserved.
- 21. ibm.com/developerWorks developerWorks®
The Package Explorer view shows the Java element hierarchy of all the Java
projects in your workbench. It provides a Java-specific view of the resources shown
in the Navigator. The element hierarchy is derived from the project's build paths. The
source folders and referenced libraries are shown for each project. You can open
and browse the contents of both internal and external JAR files.
The Outline view is useful to navigate the content of the current active editor. When
you open a file in an editor window, the Outline view displays the structural elements
of the file. If you click an element in the Outline view, the displayed content in the
editor jumps to the location of that element in the file. The Outline view's context
menu can be used in much the same way as the context menu in the Java editor.
For instance, if you have multiple fields defined in your class and select one of them
in the Outline view, use its context menu to select Source > Generate Getters and
Setters; of all the fields in the class, that specific field's getter and setter methods
will already be selected to be generated.
Use the Outline view tool bar (highlighted on the top right of the view) to sort, filter,
and hide elements of a file. You can sort the elements alphabetically, hide fields,
static fields and methods, and hide public methods and local types. The buttons are
toggle buttons, so if an element type is hidden, clicking on the button a second time
reveals the element again.
The Package Explorer and Outline views use decorator icons to describe the
elements being displayed in the view. For instance, the text field has a red square
next to it, indicating that it is a private field. The getter and setter methods have
green circles, which represent public methods. To see a table of icon decorators and
Java development
© Copyright IBM Corporation 1994, 2007. All rights reserved. Page 21 of 37
- 22. developerWorks® ibm.com/developerWorks
their meanings, use the Help Contents search function, and search for JDT icons
(Java development tool icons).
Java build path
To demonstrate the concept of the Java build path, use some of the concepts you
already learned. Create a second Java project named HelloWorld. In that Java
project, create a package named com.dw.hello. Once you have your package,
create a class using the following options:
• Source Folder: HelloWorld
• Package : com.dw.hello
• Name : HelloClass
• Modifiers : public
• Superclass : java.lang.Object
• Method stubs to create : public static void main(String[] args)
Figure 20. HelloWorld project
So far, you have nothing very interesting. Now, place your cursor inside the main
method, and type HelloHelper hello = new HelloHelper() Notice that I
have intentionally left off the final semi-colon. Save the file.
Figure 21. Problems
Java development
Page 22 of 37 © Copyright IBM Corporation 1994, 2007. All rights reserved.
- 23. ibm.com/developerWorks developerWorks®
Looking at the screen capture above, you should notice that there are problems
being indicated in the Package Explorer view, the Java editor, the Outline view, and
the Problems view. The Description in the Problems view describes what the
compiler is currently complaining about. You already know that you are missing a
semi-colon. Go ahead and add the semi-colon, and save the file.
You still have a problem... HelloHelper cannot be resolved. You created
HelloHelper in a separate project, and by default, it is not in the new project's Java
build path. To use the HelloHelper class, modify the code to which the HelloWorld
project has access. Bring up the HelloWorld project's context menu and select
Properties. Select the Java Build Path option and the Projects tab. Click the Utility
project's check box and click OK.
Figure 22. Utility build path
Java development
© Copyright IBM Corporation 1994, 2007. All rights reserved. Page 23 of 37
- 24. developerWorks® ibm.com/developerWorks
Notice the new icon in the Java editor's marker bar. There is a light bulb next to the
error's icon. This is called a Quick fix, and provides correction proposals for the
error. Click the light bulb to see the correction proposals.
Figure 23. Quick fix proposal
If you click Import 'HelloHelper' (com.dw.utilities), an import statement is added to
your class. This is only possible because you added the Utility project to the Java
build path. Now, the build path has been searched, and a HelloHelper class was
found. If there were multiple HelloHelper classes on the build path, each one would
have an entry in the Quick fix proposals. Another way to add import statements to
your code is to select Ctrl-Shift-O or bring up the Java editor's context menu and
select Source > Organize Imports. Use whichever method you prefer, and save the
file.
Figure 24. Organize imports
Java development
Page 24 of 37 © Copyright IBM Corporation 1994, 2007. All rights reserved.
- 25. ibm.com/developerWorks developerWorks®
Content Assist
Once again, place your cursor in the Java editor, this time under the hello
declaration. Type Sys and then Ctrl-Spacebar. Look at the provided matching
proposals for terminations to what you have typed. The more you type, the more the
terminations will be filtered. This again is part of the Content Assist feature. Use the
scrollbar and double-click sysout - print to standard out. This time, even the
terminating semi-colon has been added for you!
Figure 25. System out
Now place your cursor inside the System.out.println() method parameter list.
Type hello. and wait. Momentarily, completion suggestions for the hello object
should appear. Double-click getText() and save the file.
Java development
© Copyright IBM Corporation 1994, 2007. All rights reserved. Page 25 of 37
- 26. developerWorks® ibm.com/developerWorks
Figure 26. getText method invocation
There is an auto activation feature that is triggered in Java code by typing a period.
To see the Auto activation delay (in milliseconds ), Auto activation
triggers for Java, and many other code assist preferences, click Window >
Preferences > Java > Editor > Code Assist. Press F1, select Java editor
preferences and then use the scroll bar to locate the Code Assist preferences and
definitions. Again, you can use preferences to control the feature.
Figure 27. Code Assist preferences
Java development
Page 26 of 37 © Copyright IBM Corporation 1994, 2007. All rights reserved.
- 27. ibm.com/developerWorks developerWorks®
Refactoring
Every once in awhile you need to rename packages, classes, or methods, and you
want to do it without breaking your existing code, or code that references them. This
is what you call refactoring. The goal of Java program refactoring is to make code
changes without affecting the behavior of the program. Let's take a look at a few
refactoring operations.
First, modify the Utility project. Assume that you want to rename the HelloHelper
class' text field to a more mnemonic name like salutation. Right-click the text
field and select Refactor > Rename. On the Rename Field panel specify
salutation as the new name, select the check boxes for Update references,
both the rename getter and setter methods, and click OK.
Figure 28. Refactoring rename
You could have previewed all the changes that were going to be made from the
previous panel. If you navigate to the HelloClass, you find that the invocation in the
println statement has been changed to getSalutation(). So far, the application's
behavior has not been modified by the name change.
Now, create a new class in the com.dw.utilities package that inherits from
HelloHelper. Use the following options on the New Class window:
• Source Folder : Utility
• Package : com.dw.utilities
• Name : Helper
• Modifiers : public
Java development
© Copyright IBM Corporation 1994, 2007. All rights reserved. Page 27 of 37
- 28. developerWorks® ibm.com/developerWorks
• Superclass : com.dw.utilities.HelloHelper
• Method stubs to create : all unchecked
Figure 29. Helper class
Add public String ending="Goodbye"; to the class and generate Getters
and Setters for the new ending String.
Figure 30. Helper code
Have you ever wanted to know what the class containment was for a resource that
you were working on? There is a Hierarchy view that presents you with the
inheritance tree of an object. Select the ending field in the hello class and do one
of the following:
• Press the F4 key
Java development
Page 28 of 37 © Copyright IBM Corporation 1994, 2007. All rights reserved.
- 29. ibm.com/developerWorks developerWorks®
• Select Open Type Hierarchy from its context menu.
• Select Navigate > Open Type Hierarchy from the main menu.
Figure 31. Hierarchy view
In the hierarchy tree pane, you can see that, as defined by Java inheritance,
ending is contained by the Hello class, which is contained by the HelloHelper
class, which of course, inherits from the Java root Object. The hierarchy tree pane
has a toolbar that lets you Show the Type Hierarchy, Show the Supertype Hierarchy,
Show the Subtype Hierarchy, show Previously Type Hierarchies and change the
orientation of the view, or eliminate the member pane.
The member pane shows the members of the selected hierarchy tree object. The
member pane toolbar allows you to Lock View and Show Members in Hierarchy,
Show All Inherited Members, Sort Methods by the Defining Type, Hide Fields, Hide
Static fields and Methods, or Hide Non-Public Members.
If you think about what you have done in the code, you have extended the
HelloHelper class with a new field and with accessor methods. Assume that after
further investigation you realize you really don't want a new class, just the
functionality. Click anywhere in the Helper class to make it the active window. From
the main menu, select Refactor > Pull Up and then select the check boxes for the
field ending, and methods getEnding and setEnding. You could click Finish, but
instead, click Next.
Figure 32. Refactoring pullup
Java development
© Copyright IBM Corporation 1994, 2007. All rights reserved. Page 29 of 37
- 30. developerWorks® ibm.com/developerWorks
This page of the wizard shows the methods that will be removed from the Helper
class and added to the HelloHelper class. Click Next.
Figure 33. Refactoring methods to be removed
Java development
Page 30 of 37 © Copyright IBM Corporation 1994, 2007. All rights reserved.
- 31. ibm.com/developerWorks developerWorks®
This final page is a preview page that shows you the original class and the code to
remain after the refactoring operation. Click Finish. The HelloHelper class now
contains all the code that had been in the Hello class (the String and the accessor
methods). You can safely delete the Helper class; go ahead and do it.
As one last refactoring operation, rename the HelloHelper class to Helper. In the
Package Explorer view, select the HelloHelper class and from its context menu
select Refactor > Rename. This time, type Hello as the new name, and select the
Update references check box. Click OK.
Figure 34. Renaming HelloHelper
Verify that the import statement in the HelloClass has been updated. These are only
a few of the many possible refactoring actions that can be performed in the
workbench. For other actions, search the Help Contents for JDT actions and from
the result, click Refactor actions.
Running Java applications is covered in Part 5 of this series, but if you would like to
see your HelloWorld application run, select HelloClass.java in the Package
Explorer, and from its context menu select Run > Java Application. You need to
add the Console view to your workbench to see the output.
Figure 35. Running Hello World
Java development
© Copyright IBM Corporation 1994, 2007. All rights reserved. Page 31 of 37
- 32. developerWorks® ibm.com/developerWorks
Figure 36. Console view output
Section 5. Miscellaneous hints and tips
Java development
Page 32 of 37 © Copyright IBM Corporation 1994, 2007. All rights reserved.
- 33. ibm.com/developerWorks developerWorks®
Editor tips
Let's cover a few Java editor details that can help during the development process.
In the development process, especially in Java, every once in awhile, you misplace
a beginning or end brace. Clicking inside a begin brace, or outside a close brace,
highlights its matching brace. The marker bar also shows selected areas with a
darker color. The default bracket marker is a light grey (almost unnoticeable) box
around the matching brace, if it has a matching brace.
Figure 37. Highlight matching brackets
To improve visibility you might want to change the color of the highlight marker.
Select Window > Preferences > Java > Editor. Under Appearance color options,
select Matching brackets highlight, and click Color. A color palette pops up and
you can pick a different color for your brackets.
Figure 38. Change highlight color
Java development
© Copyright IBM Corporation 1994, 2007. All rights reserved. Page 33 of 37
- 34. developerWorks® ibm.com/developerWorks
The overview ruler is on the right margin of the Java editor. While the marker bar
shows markers for the visible editor lines, the overview ruler shows markers for
problems and tasks that may be outside the visible area, but in the file, on a
proportional scale.
Figure 39. The overview ruler
Java development
Page 34 of 37 © Copyright IBM Corporation 1994, 2007. All rights reserved.
- 35. ibm.com/developerWorks developerWorks®
Have you ever lost track of a method or class in a large project, or wanted to know
how many times a method was invoked in a project? The Java Search feature can
assist you in this determination. Select Search > Java from the main menu. This lets
you find references, declarations, and occurrences of Java packages, types,
methods, or fields. You can limit the search to the workspace, a selected resource
(such as a project or package), the enclosing project of the currently selected
resource, or a working set. The Java search is supported by an index that is
maintained as resources are created or modified in your workspace.
Figure 40. Java search
Java development
© Copyright IBM Corporation 1994, 2007. All rights reserved. Page 35 of 37
- 36. developerWorks® ibm.com/developerWorks
Search the Help Contents for JDT Tips and Tricks for lots of additional useful
information on using the workbench.
Section 6. Conclusion
In this tutorial you have covered some basic Java development features. Be sure to
further explore the functions you have touched on in the tutorial. Create a test
workspace and use the wizards, context menu options, and features to expand your
familiarity with your development options.
I hope you have found this tutorial helpful, and wish you luck as you prepare for your
certification test.
Java development
Page 36 of 37 © Copyright IBM Corporation 1994, 2007. All rights reserved.
- 37. ibm.com/developerWorks developerWorks®
Resources
Learn
• Get certified as an "IBM Certified Associate Developer". Check out the
objectives, sample assessment tests, and training resources for test 255,
"Developing with IBM Rational Application Developer for WebSphere Software
V6".
• To learn more about the Eclipse project, go to Eclipse Project Frequently Asked
Questions..
Get products and technologies
• Download a free trial version of IBM Rational Application Developer.
• Build your next development project with IBM trial software, available for
download directly from developerWorks.
Discuss
• Participate in the discussion forum for this content.
• Participate in developerWorks blogs and get involved in the developerWorks
community.
About the author
Mr. Bobby McChesney
Bobby McChesney was an Education Specialist with IBM's Application Development
team. He specialized in WebSphere Application Server Version 6 and Rational
Application Developer for WebSphere® Software courses. Bobby also taught the
Java Servlet, JavaServer Pages, Struts, JavaServer Faces, and Enterprise
JavaBeans programming courses. He currently works in the WebSphere
Development organization.
Java development
© Copyright IBM Corporation 1994, 2007. All rights reserved. Page 37 of 37