03-Java Development Tools
03-Java Development Tools
ibm.com/developerworks/
April – June 2006
1
Presented by IBM developerWorks
ibm.com/developerworks/
April – June 2006
2
Presented by IBM developerWorks
JDT perspectives
The most useful perspectives
for Java development are Java
and Debug.
There are also the Java
Browsing and Java Type
Hierarchy perspectives.
We'll look at the Java
perspective now; we'll cover the
Eclipse Debugger later.
Class outline
Syntax-aware
Java editor
Class hierarchy
3
Presented by IBM developerWorks
4
Presented by IBM developerWorks
Code generation
Code assist
5
Presented by IBM developerWorks
Quick fix
For many common problems,
Eclipse can offer fixes for you.
If a package statement doesn't
match a .java file's location,
Eclipse will move the file or
update the package
statement.
If you're missing an import
statement, Eclipse can
automatically add it.
If a Quick Fix is available, the
red X will have a light bulb icon
behind it.
Organize imports
If you use a Java class without
a corresponding import
statement, Eclipse will add
them for you automatically.
By default Eclipse imports
java.io.OutputStream, not
java.io.*.
If you remove all instances of a
class and invoke Organize
Imports again, Eclipse removes
the import statements you
don't need.
6
Presented by IBM developerWorks
Code refactoring
Globalization
Eclipse has an "Externalize
Strings" function that helps you
manage translation or
localization of your projects.
7
Presented by IBM developerWorks
ibm.com/developerworks/
April – June 2006
8
Presented by IBM developerWorks
If you click Next after you give your project a name, you'll see other
options. You can use these to set the classpath of your project,
among other things.
9
Presented by IBM developerWorks
10
Presented by IBM developerWorks
11
Presented by IBM developerWorks
12
Presented by IBM developerWorks
A shortcut
You can create a new package
and a new class at the same
time.
Simply create a new class and
enter a new package name in
the wizard.
13
Presented by IBM developerWorks
14
Presented by IBM developerWorks
Click Java Application, then New. You'll see a dialog that lets you
set all the details of your application:
The Arguments tab defines command-line arguments, The Classpath
tab lets you add JAR files to your classpath, and so on.
The run configuration must point to a Java class with a main()
method. If it doesn't, Eclipse can search your project for a class that
does.
15
Presented by IBM developerWorks
ibm.com/developerworks/
April – June 2006
Scrapbook pages
Scrapbook pages
You can create a scrapbook
page with the Java tools. A
scrapbook page lets you enter
and execute lines of Java code
without building a class to hold
them.
The wizard to create a new
scrapbook page is under NewÆ
JavaÆJava Run/Debug.
16
Presented by IBM developerWorks
Scrapbook pages
You can highlight some code, right-click on it, then choose Inspect,
Display or Execute.
Our sample code here is System.out.println
("Here's the value of PI: " + Math.PI);
If you choose Execute, the selected code is executed. In this
example, we've highlighted the entire line of code; executing it writes
to the console.
Scrapbook pages
If you choose Inspect, the
scrapbook page shows you the
value of whatever you've
highlighted.
In this example, we've only
highlighted Math.PI, not the
whole line of code.
Display inserts the value of
whatever you've highlighted.
17
Presented by IBM developerWorks
ibm.com/developerworks/
April – June 2006
18
Presented by IBM developerWorks
Select Java/JUnit on the left and TestCase on the right, then click
Next.
19
Presented by IBM developerWorks
When you create a JUnit test case, you name the test case (it's a
Java class) as well as the Java class tested by the test case.
Eclipse gives you a list of all the public methods in your class and its
superclasses. You decide which ones should be part of the JUnit test
class.
20
Presented by IBM developerWorks
21
Presented by IBM developerWorks
The results of running your test case appear in the JUnit view.
Green is good…
You can also create and run JUnit TestSuites. A TestSuite is
an ordered collection of TestCases.
Using JUnit
You define more TestCases and TestSuites as your
project progresses.
You run the JUnit tests to make sure any changes you've
made haven't broken your code.
22
Presented by IBM developerWorks
ibm.com/developerworks/
April – June 2006
Using Ant
Ant (ant.apache.org) is an XML- and Java-based
build tool.
Designed to have the same functionality as make without its quirks
You don't need a tab character at the start of each line, for example.
You can extend Ant to do other tasks if you want.
An Ant build file (named build.xml by default) can
define a number of targets.
You can define which target gets built from the command
line (or the Eclipse equivalent), or let Ant figure out which
one should be created.
23
Presented by IBM developerWorks
Using Ant
Once you've created your
build.xml file (or whatever
you choose to call it), you can
right-click on it and choose Run
Ant…
Using javadoc
You can export your project to
javadoc.
When you do this, Eclipse runs
javadoc against your code
and exports the generated files
to the directory you choose.
24
Presented by IBM developerWorks
Using javadoc
When you generate the
javadocs, you specify which
packages and classes should
be processed.
You can also decide which
class members are processed
(public, protected, private)
Using javadoc
You can customize the files that
are generated, such as index
pages or navigation bars.
If you want, you can create links
to the standard Java libraries.
25
Presented by IBM developerWorks
Using javadoc
Summary
26
Presented by IBM developerWorks
Summary
We've covered (although very quickly) the Java
development functions in Eclipse, including:
Various automatic coding features
How to create and run Java code
Using scrapbook pages
Automating testing with JUnit
Using ant and javadoc inside Eclipse
27