UCSCBaskin School of Engineering  
General Information Events, News & Organizations Degrees & Departments Research Classes Admissions & Advising People & Jobs Administration
CMPS 012A/L - Week 4 Lab

Eclipse IDE

For the week of Jan 30-Feb 3, 2006

Up until now, we've been focusing on simple text editors for Java. There are other editors that are specially designed to help the programming process. These advanced editors often fall under the category of IDE, or Integrated Development Enviroment. Eclipse is one such IDE which helps you by coloring your text and allowing you to auto-complete what you type, among other things.

Additional Information

If you would like, you may download Eclipse for your Windows machine at home from Eclipse.org.

Procedure

  1. Start Eclipse by typing "eclipse" at the command line.
    1. Accept (click OK) the default workspace suggestion.
    2. Close the "Welcome" window by clicking on the "x" on the "Welcome" tab.
  2. Create a project:
    1. File/New/Project/Java Project/Next
    2. Give it the name "Craps".
    3. Under "JDK Compliance" click "configure default".
    4. Select compiler compliance level 5.0.
    5. Click Apply, then Yes (to rebuild), then OK.
    6. Click Finish.
    7. You should now be in the "Java Perspective". There should be several window panes, and in the upper right corner should be a small box with "Java" in it. If you aren't in the "Java Perspective", you can get there by selecting Window/Open Perspective/Java.
  3. Import an existing source file:
    1. File/Import/File System/Next
    2. Browse to /afs/cats/courses/cmps012a-cm/eclipse then click Choose. (Or you may download Craps.java here--right click on the link and choose Save)
    3. Click on the eclipse folder icon then select Craps.java in the right hand pane.
    4. If the "Into folder" doesn't already show "Craps" then click on the browse button for that field and select "Craps" then click OK.
    5. Click Finish.
  4. Open Craps.java in an editor.
    1. Click the "+" next to Craps in the Package Explorer (left pane), then click the "+" on "(default package)" then double click Craps.java. An editor pane should open with Craps.java. (Note that on some platforms the "+" will appear instead as a small triangle.)
  5. Fix two problems in Craps.java indicated by the red circle with an "x" indicating an error and a yellow circle (if you look close I believe it is a yellow light bulb) indicating that Eclipse has a suggestion as to how to solve the problem.
    1. Scoll down to the first light bulb (yellow blob) in the left margin of the editor pane. Notice the little red squares on the right margin of the editor pane. They show where the errors are in the complete file. Try clicking on one.
    2. Click ONCE on the first light bulb. Give it a few seconds. It will show several suggestions.
    3. Select the one suggesting you need to import java.util.Random, then double click it. This will make the insertion for you.
    4. Scroll down to the next light bulb. (Look for the one remaining red square in the right margin.) Click on the light bulb. Notice it shows you the methods that could be called. Select the correct one and then double click it.
    5. Save the file and you should no longer see any red circles with white "x"s in them.
  6. Run the program.
    1. Select Run then Run...
    2. Select "Java Application" then click New.
    3. In the name field put: Craps
    4. If "Main class:" isn't already Craps, type it in or click Search... and select Craps.
    5. Click "Run".
    6. A console will appear. It may take a few seconds to get started. The console should eventually show a prompt for the seed. You may need to click in the console pane before you can enter any input.
    7. Play a few rounds of the game then end by betting 0.
  7. Add a new method using refactoring.
    1. In the method rollDiceUntilWinOrLose, select the lines after the comment "// roll until point or 7" up through the end of the if-else statement. You can get there quickly by clicking on the method name in the rightmost pane labelled "Outline".
    2. Click menu Refactor and select Extract Method.
    3. Give the method a name. I suggest, rollUntilPointOr7.
    4. Click the "default" Access Modifier button then click OK.
    5. Notice how it figured out what needed to be passed in and that the result needed to be assigned to variable winLose.
    6. Click File/Save. (If Save is not available then the file was already saved automatically.)
  8. Try out the debugger.
    1. Click menu Run then Debug Last Launched.
    2. Scoll the Craps.java pane until you see the while loop in main.
    3. Set a break point by double clicking in the left margin next to the line declaring "boolean won". A small blue check and ball (or something - I can't be sure what it is :-) will appear in the margin.
    4. Click in the console window and enter a seed and an initial bet. This should bring you to the break point.m (Click "Yes" when it asks to go to the debug perspective. You can have it remember this answer if you wish.)
    5. Notice all of the local variables are displayed in the Variables pane.
    6. Try some of the various continue options (continue, step-into, step-over). They are the icons along the top of the pane labelled "Debug". If you point the mouse at one without clicking and wait a few seconds, a text descriptor will pop-up.
    7. When you are done either end the game normally by betting 0, or click the terminate icon (red square), and return to the "Java Perspective" by clicking to the left of the "Debug" in the upper left corner, or select Window/Open Perspective/Java.
  9. See some more name completion in action.
    1. Create another file just to play around with typing. File/New/Class. Call it "Fiddle" or whatever you want. Check the box saying you want it to create a main method. Click Finish.
    2. In the body of main type "String str;"
    3. On the next line type "str." then just wait. A window will pop-up showing all of the possible operations you can perform on a string. Type a little more so you have "str.subs". Notice how it just shows those methods or operations that could fit with what you have typed.

General info · News · Events · Degree Programs · Research · Classes · Admissions · Advising · People · Jobs · Administration
SOE Webmail · SOE SSH · SOE Wiki · Search · Sitemap · Contact us · Driving directions · Privacy · UCSC
© Baskin School of Engineering, University of California, Santa Cruz
1156 High St., Santa Cruz, CA 95064 · (831) 459-2158 · webmaster@soe.ucsc.edu