You are on page 1of 28

Getting to Grips

with Eclipse
(and meeting the fairies)
Generating UML Diagrams
• UML class diagrams are very useful

Person
name: String
age : int
address : String

• But there’s no need to spend ages drawing them ...


• ... when Eclipse can generate them automatically.
Generating UML Diagrams
• To generate UML diagrams, simply...
• ... select the package you are working with
• Select File … New… Other…
• Look for the ObjectAidUMLDiagram folder and select
Class Diagram.
• Give the diagram a name and select finish.
• You can now drag your blank file onto the canvas
Auto Getters and Setters
• Don’t waste time writing getters and setters ...
• ... Let Eclipse generate them automatically.
• Simply open a class that has some instance variables
• Select Source .... Generate Getters and Setters...
Auto Getters
and Setters
• Select the
instance variables
you want to
generate getters
and setters for
and press OK.
Auto Getters and Setters
• The getters and setters will be inserted into your
code.
• However, you may notice that the word this is not
used in the getters as it should be.
Auto Getters and Setters
• Simply delete the getters and setter that have been
inserted and start again.
• Select Source... Generate Getters and Setters...
Auto Getters
and Setters
• Once you have
selected your
instance variables
click on the Code
Templates link in
the bottom right
hand corner
• Select Java
Code Style
• Then tick the
Enable
project
specific
settings box
• Then tick the
Qualify all
generated
accesses with
this box
• Press Apply
and select OK
Auto Getters and Setters
• You’ll be returned to
this window
• Select OK
• The correct getters
and setters will now
be inserted
Correct Indentation
• As you know incorrect indentation annoys me ...
• ... but for some people it seems to be a way of life.
• Don’t panic, help is at hand.
• The indentation Fairy
Correct Indentation
• Take one messy program, select the code
• Select Source ... Correct Indentation ...
Correct Indentation
• And the Indentation Fairy works her magic
Tidy Code
• Explore other
ways to tidy
your code by
Selecting
Souce ...
Clean Up...
Making an Executable JAR File
• Select the package you are working with
Making an Executable JAR File
• Select File... Export.... And select JAR File
Making an
Executable
JAR File
• Select the package
• Use Browse... to
select where to
save the file
• For now accept
the other default
settings
• Select Next
Making an Executable JAR File
• Select Next
Making an Executable JAR File
• Browse to select
the file which
contains main()
• Select Finish and
your executable JAR
is complete
Smart Typing
• The smart typing fairy is waiting for you to call her
• Simply type something and the press Ctrl Space
The syso fairy
• In Eclipse type syso the hit Ctrl and the space bar.

• Try it and see what happens … it’s great


Quick Fix
• The quick fix fairy is waiting for you to call her
• Simply move your cursor to the error and the press
Ctrl 1
Quick Fix
• Which came first the chicken or the egg?
• Which do you write first, the method call or the
method?
• Let Eclipse do all the hard work.
Scrapbook Pages
• Scrapbook pages are great and easy to use.
• Go to File -> New -> Other
Scrapbook Pages

• Select Java
• -> Java Run/Debug
• -> Scrapbook Page
Scrapbook Pages

• Enter a name
Scrapbook Pages

• Now you can


enter any java
code
• Select it
• Right click
• And run it
(execute)
Tutorial Time
• Now it’s your turn ...

You might also like