Part 2 - Eclipse

Now you should start Eclipse. This is a Java IDE (Integrated Development Environment) that is used world-wide. It has a number of very useful features including automatic compilation, error detection, built-in debugger, autocomplete, and many other features.

Eclipse is available for free for your home machine, should you want some alone-time with it. Just go to the Eclipse website for download.

Start eclipse

Just run it from the command line. Open up a terminal window and type:

eclipse &

Alternatively, choose it from the graphical Development menu.

You should just accept the default for workspace. (Usually ~/workspace/) Please do not select your csci151 folder as your default workspace. It'll take a bit to start up.

Do tutorial

From the Eclipse Welcome page, click Tutorials > Create a Hello World Application. Follow the instructions to make your very first eclipse Java program. Good times.

Customize Eclipse preferences

Until you get more familiar with eclipse and figure things out on your own, please make the following changes to your preferences to make life easier. Start by selecting the menu Window   >   Preferences (On a Mac, it is located in Eclipse   >   Preferences.

Set preferences

First, let's deal with auto-completion and cursors. Click on the triangles in front of "Java", "Editor" and click on "Typing".

Notice that it will automatically insert closing braces, quotes, and the like by default. I recommend that you keep these enabled. It will take a little getting used to, but prevents annoying little bugs.

The second section "automatically insert at correct position" has things that I really like to enable. When you type either ; or a brace, it'll jump to the right spot for it most of the time. It's pretty nifty, try it out!

Fixing output to be more sane

By default, Eclipse uses tabs for indentation. However, it displays them as being only 4 spaces, when most other things will display them as 8. A minor detail, but changing this will make things much more readable outside of Eclipse. The easiest way is to change the preferences "Java", "Code Style", "Formatter" and then select "Java conventions" as the Active profile. If you change only one setting, make it this one!

Code Style settings screen

You can also get Eclipse to reformat your code when you are working on it in a number of ways. You can highlight a section of text and then hit "ctrl-I" or use the menu "Source", "Correct Indentation". You can also use the "Source", "Format" command to make similar changes. You can also have it automatically reformat your code each time you save. Go to "Java", "Editor", "Save Actions" and check the box marked "Perform the selected actions on save". You can have just reformat the sections of code you have been working on, or you can have it take care of the entire file.

Javadoc

If you take advantage of the auto-Javadoc comments, you'll probably want to also change the settings under "Java", "Code style", "Code Templates", "Comments", "Overriding methods" to match "methods". (Just copy and paste the Pattern window contents from "Methods" to "Overriding methods".)

Change the default build path

In recent versions, Eclipse likes to put the *.class files in a different folder than your *.java files. However, this makes things a bit harder to go between eclipse and a normal editor. Change the preferences by selecting "Java" and "Build Path" and change the value of 'source and output folder' radio button to be "Project" instead of "Folder". Do not change the value of Source folder from src or Output folder from bin -- this is the radio button only. If you change only two settings, do this one too!

Build Path settings screen

do some editing

While you are working on stuff, you'll probably find that there are lots of functions you might want to use via the pull down menus. Note that the keyboard shortcuts are listed on the right hand side. Learning to use them will speed up your work.

As a reference guide for some such shortcuts and nifty things, I'll refer you back to the eclipse tutorial, and this list here:

  • Note the smart insertion of things like ‘;
  • Quick fix using ctrl-1 (thats a one)
  • Rename all instances of a variable in one fell swoop using Refactor   >   Rename
  • Add/remove comments (ctrl-/)
  • Use ctrl-space to autocomplete names of classes and methods. Try typing “sysout” and then ctrl-space
  • Create a new class from interfaces or from a superclass using the appropriate textboxes under File   >   New   >   Class
  • Debug in style with breakpoints, variable examination, watchpoints (see this tutorial to learn more.)
  • Set arguments for a command line Run  >  Run configurations…
  • Generate getter and setter methods using Source  >  Generate Getters and Setters
  • Generate constructors using Source  >  Generate Constructor using Fields
  • Maximize the current area, or unmaximize using ctrl-m.
  • Display line numbers by right-clicking on the left margin of the editor and selecting that setting

« Previous Next »