Introduction to Eclipse

You now have many programs under your belt and chances are you've been doing your coding in Kate and compiling using javac. As programs get more complicated and you have more classes to deal with, it will be helpful to have additional tools to help you develop your programs. One very useful thing is to use an "Integrated Development Environment" (IDE). The purpose of an IDE is to hide a lot of the mechanics of the language from you so you can focus on solving the problem at hand. A good IDE will increase your efficiency and make coding much easier. (Think how much more difficult it would be to code in Notepad versus Kate).

Goal: Learn to use an IDE, because it will make you much happier!

A very popular (and free) Java IDE is Eclipse. Eclipse is very powerful and has many features that are easy to use once you get the hang of it. For example, Eclipse will automatically compile your code as you type. This means if you leave out a semicolon, you will know immediately. Another useful feature in Eclipse is "code hinting." As you type the name of a method, Eclipse will populate all the possibilities based on what you've typed so far. This means you will have to refer to other files far less frequently, which can be very helpful for large programs. Another nice feature is access to a debugger. The debugger lets you run your code line by line and gives you information about the variables to help you figure out why your code is not working properly. Becoming comfortable and proficient with Eclipse will not only help you in CS015, but in future CS courses you might take, and in any jobs you may hold in the CS in the future - many, many, many companies use Eclipse for writing Java code.

In this lab, you'll be setting up Eclipse, learning some of its very useful features, and then writing a very simple program. Setting up a project in Eclipse can be a bit confusing the first time, so we are going to walk you through it step by step. The TA's have pre-configured your Sunlab accounts to allow your java to communicate with our support code fairly easily. However, you'll have to do a bit of configuration yourself to get our stencil code into Eclipse and tell Eclipse about our support code. The first few times you try to do this could be frustrating but the additional time you spend setting things up will definitely be made up by Eclipse's additional functionality.

Check Point 1

  1. Start Eclipse by typing 'eclipse' into your shell. If this is the first time you're running Eclipse, you will prompted for where to put your workspace directory with a small window that says "Select a workspace". Simply use the default (it should be something like /home/<yourlogin>/workspace). If you then see a Welcome screen, close it by clicking the "X" located on the tab.
  2. On the right hand side there will be tabs for Task List and Outline. Close both of them.

The Eclipse Interface

Eclipse Interface
  1. Package Explorer: This is the directory tree for your workspace. All of the projects, their packages and the Java files can be seen here. Projects can either be open or closed. If a package is open, it is actively compiled when you edit the Java files. If a project is closed, you can not access any of the files in the project until you open it. You can open and close a project by right clicking and selecting open/close project on its root project tag (open/close project).
  2. Editor region: This is where your active file is found. Eclipse has a powerful editor that will provide all the functionality you expect. The commands for the editor are your traditional windows shortcuts (ie: CTRL + S is save, CTRL + C is copy, etc). If you have multiple files open, there will be tabs at the top that you can use to navigate between files.
  3. Console region: This is where you can get information from Eclipse. By default, you should have a Problems tab, a Javadoc tab, and a Declaration tab. Ignore the Javadoc and Declaration tabs for now, but keep in mind that you can install the Javadocs on Eclipse and never have to use the website again. If you have Javadocs installed, when you click on something, let's say a JPanel, the entire document will show up under the Javadocs tab. Compile errors and warnings will show up in the Problems tab. When you run your program, a Console tab will appear to show printlns and stack traces. You can choose to always view it by going to Window » Show View » Console.