Survey

Let's begin the lab by collecting a little information from you. (If you missed your lab session, please take a few minutes to fill out the survey on your own. Your answers will help us tune the course so that it works better for you!)

 


Introduction to Eclipse

Overview

Up until now, we've used DrJava throughout CIS 120. Although DrJava with its Interactions Pane is a nice IDE (Integrated Development Environment) for introductory purposes, it lacks many of the features found in professional quality IDE's, such as a good debugger. In this lab we introduce a powerful IDE called Eclipse which you will find to be a very useful tool, especially when working on large projects. Like DrJava, Eclipse is free and multi-platform (unix, Mac, Windows).

Is Eclipse Required for this Course?

No, it's optional: you are free to use whatever IDE you prefer for the rest of the course. But we strongly recommend that you take the trouble now to come to grips with it. You may find it a bit confusing initially, but it is really not hard to use in a basic way, and it is much more pleasant and helpful than DrJava once you're used to it.

How to Set Up Eclipse

A First Taste

  1. Start Eclipse
  2. Since this is the first time you're running Eclipse, you'll be asked where you want your "workspace" to live. Accepting the default is fine.
  3. Since this is a new workspace, Eclipse will begin by displaying a "Welcome" screen.
  4. Now let's do the same thing again with a more interesting program.
  5. Try adding a couple of new classes, by doing File -> New -> Class. (For example, try adding a Merchant class that extends the class Character and overrides one of its methods in some simple way.)

Learning More

  1. The "Welcome Screen" that we skipped at the beginning is an excellent starting point for exploring further. You can get it back by choosing "Welcome" from the Help menu. Spend a few minutes now skimming the Overview section.

More Information

Perspectives

Browsing a Project

Helpful Features While Coding in the Code Pane:

Running your code

Debugging

The eclipse debugger is powerful. To learn it we'll debug Driver.java, a simple program (with unfortunate bugs) for printing some information about movie tickets. You'll also need Ticket.java and MovieTicket.java. We will set breakpoints (at lines of code where we want Java to pause during execution so we can examine the values of variables and so forth).
  1. Create a new project and create a new class called Driver in the project.
  2. Copy the contents of the Driver.java file to that class (or alternatively copy Driver.java to the directory of the project and refresh the project). Do the same for Ticket and MovieTicket.
  3. You will set breakpoints to suspend the execution of your program. To add a breakpoint to any line in the code, press Ctrl+Shift+B while you are on that line. (Alternatively, choose Run -> Toggle Breakpoint from the menu.) For our purposes, add a breakpoint to the first line of the main method in Driver.
  4. For debugging to work, you have to run your program in Debug mode. To do that you can press Alt+Shift+D, J or choose Debug As -> Java Application from the context menu. Once you run your program, it will execute up to first breakpoint it encounters and stop at that point, Eclipse will ask you to switch to Debug perspective automatically as it happens.
  5. Debug perspective contains a call stack at the top left corner, a summary of variables in top right corner. You can also get a list of breakpoints at the same place. At the bottom, you can see the console which will show any output.
  6. Our aim will be to analyze the values of various objects to see what is happening to them as the program executes. There are several ways to do this:
  7. You also have different options to continue running your code. You can access the buttons explained below on the Debug pane.