The Penumbra Perspective
Now that you have checked out your first project, you should
familiarize yourself with the workbench. You should see the Penumbra
perspective (notice the name "Purdue Penumbra" in the title bar). If
this is not the case, you should switch to this perspective by
selecting Penumbra > Penumbra Perspective.
Elements of the workbench
There are five main parts that are of concern for you:
1. menubar at the top of the window
- it includes the Penumbra menu, which should
become very handy
2. toolbar underneath the menubar
- it provides shortcuts to functions in the menubar
that have been symbolized with icons
- notice the highlighted Penumbra toolbar
3. Penumbra Package Explorer on the left side
- displays all projects in your workspace
4. hierarchy view on the bottom left side
- this will show the object-oriented hierarchy in
which the classes in your project are organized
5. editor on the right side
6. console window on the bottom
- will display output and allow for input when you
run programs
Using the Penumbra Package Explorer
At first, you should only see one object (probably called "project1")
with a little plus sign in front of it. Click on the plus sign to
expand the object and see the objects it contains. Do this to all
children until the view is completely expanded. You should now see that
there are some classes listed in the default package. Notice also that
you can see an outline of the class. All data members and methods are
displayed. In order to open a class or a specific method, simply
double-click on its name.
Using the Hierarchy View
The hierarchy view will show you an object-oriented view of your
current project. In the first couple projects you will probably not
need this view, but it will soon become extremely useful. All classes
in Java, except the Object class, extend another class. If a class does
not specify in its declaration, which class it extends, it will always
extend the Object class. Hence, in your first project you will probably
see one class that extends the Object class. If you have multiple
classes in later projects can you simply drag and drop a class onto
another to make the first class extend the second class. If you wish a
class not to extend another class just drag it into the white space of
the hierarchy view.
Using the Java Editor
A Java editor containing the file you just selected should have opened
up in the editor area on the right side. Please select Penumbra
> Penumbra Perspective (alternatively you may press Ctrl +
Alt + P) again. This should hide some of the menus you do not
need. Using the editor is just like using any text editor. However,
there are some additional features that should help you write programs.
1. Syntax highlighting
By default, the editor analyzes your code and highlights
certain elements to make it easier to read. For example, it
highlights keywords in purple, comments in light blue or light
green, and strings in blue.
2. Error detection
When the editor finds an expression that it does not know
how to evaluate, it will underline it with a red line. You might not
be able to run a program before all errors are fixed. If the editor
thinks a line is unnecessary, it will underline it in yellow.
3. Quickfix
Usually, when the editor detects an error, it will also
attempt to present you with a solution. To do so, the editor will
display a yellow light blub on the left edge of the line in
which the error occured. Clicking on the bulb once will open a menu
that will offer you different solutions. Selecting one of these
solutions will immediately alter your code (however, you can always
undo the changes).
4. Formatting your code
Formatting your code is not only good programming practice
but will also help you determine the location of errors.
Fortunately, Eclipse has a functionality that will allow you to
automatically format your code. To do so select Penumbra >
Format Code (alternatively you may press Ctrl + Shirt + F).
5. Organizing Imports
Java comes with a wealth of predefined classes that you can
use. To do so, you will have to import the classes so your Java
compiler knows about them. Ordinarily this involves looking up where
these classes are located. This is not the case in Eclipse. If you
are using a class that Eclipse does not recognize, simply select Penumbra
> Organize Imports (alternatively you may press Ctrl +
Shirt + O). Eclipse will automatically import all required
classes, if they exist.
6. Using auto-completion features
There are two coding features that should make your life a
lot easier.
1. Type a keyword or part of a keyword and press Ctrl + Space.
Eclipse will show you a list of elements that you may wish to use.
For example, if you type "for" and press the two keys simultaneously,
it will show you a list of predefined for loops. Selecting one of
them will insert the loop into your code.
2. When using member methods or data members of classes, we use the
dot operator in Java (e.g., MyFirstClass.printHelloWorld()).
Oftentimes we know that there is a method we would like to use, but
we cannot remember its exact name. If you are not sure, simple type
the name of the object you are working with followed by a period and
wait for a moment. A list will appear that shows all members that you
may use.