CSE131 Lab 0: Introduction


In completing this module, you will...


  1. Log onto a PC in CEC, which is located on the 2nd floor of Sever Hall.
  2. On your H: drive, create a folder called cse131, in which to save the provided portions of CSE131 labs.
  3. To get the provided code for Lab 0, download the file lab0.zip and save it in the cse131 folder you just created.
  4. If you own a computer and want to set it up for CSE131, see these instructions for installing Java and Eclipse at home. In CEC, you'll be using your H: drive, but at home it will most likely be your C: drive. For information about transferring files back and forth, read about using the CEC file system from home.


Part I: Getting Started with Java in Eclipse

Professional software developers use an Integrated Development Environment (IDE) that includes a text editor (for creating source code), a compiler (for translating source code into executable code), and a debugger (for finding errors). In CSE131, we'll be using Eclipse, a popular IDE that supports programming in Java. This part of the lab explains how to get started using Eclipse.

  1. Start Eclipse: In CEC, click on the Start button and look under "All Programs", "Programming" to start up eclipse-3.2. The first time Eclipse starts, it will be slower than usual. You will be asked where you want your workspace to be. We recommend using the default location, and checking the box so you won't be asked again. After Eclipse starts up, click the 'X' on the "Welcome" tab at the top to close the welcome screen.

  2. Create a new project: Pull down the File menu and select "New > Project..." In the "New Project" window, select "Java Project." (You may need to open the "Java" folder in the dialog box first.) Click "next." In the "new Java Project" dialog box:
    1. Type the project name "CSE131"
    2. JRE stands for "Java Runtime Environment." There are different versions of the JRE. This semester, we are assuming that everyone will use Java 1.5 (also known as 5.0) or later. Make sure that the JRE box shows that it will use the default JRE (either Java 1.5 or 5.0 or later). If it shows something older (like 1.4), click the link "Configure JREs..." to show a "Preferences (filtered)" dialog box, in which you should change the JDK complience level to either 1.5, or 5.0 or later. [If you are running Eclipse at home (not through CEC), you may discover that 1.5 or 5.0 is not a choice, in which case you will either need to point Eclipse to the newer JRE (using the "search..." button on the dialog box, or you will need to cancel project creation, close Eclipse, and download a new JRE from Sun Microsystems. See this information about installing Eclipse at home for details.] Click OK in the "Preferences (filtered)" dialog box.
    3. Under 'project layout', make sure you select 'Use project folder as root for sources and class files.'
    4. Click "finish" in the "New Java Project" dialog box. If Eclipse asks if you want to switch to the Java Perspective, click "Yes."

  3. Import the provided code into the project: You should see a "CSE131" project in the Package Explorer at the left side of the Eclipse window. Select the project by clicking on it, and then choose "Import..." from the File menu. Select "Archive file" from the "General" list, and click "next." Using the "browse" button at the top, select the lab0.zip file that you downloaded into the cse131 folder on your H: drive. Click "finish."

  4. Look at the source code: In the Package Explorer, open up the CSE131 project by clicking on the '+' sign or little triangle to the left of the project name. You will see that it contains a package called lab0. Expand that too, and double-click the file named RobotController.java to open it. Look at the source code in the middle window. You'll see instance variables, methods, and a main method.

  5. Run the program: Right click on RobotController.java and select Run as -> Java application. You will see a map of some of the Engineering buildings. The program also provides a "methods" menu that contains a "guideRobot" menu item. Select that menu item. The program should create a robot, and you should see the robot start to move.

  6. Compiling programs: In general, before you can execute a Java program, it must first be compiled (translated) into byte code that can be executed by the Java interpreter. A program that performs this translation is called a compiler. Eclipse checks your files to see if they will compile, and it marks errors so you can correct them. If you position the mouse cursor over an error icon or a red underline, a description of the error will be displayed.

    Try typing some random text in the file to introduce an error. You should see an error icon appear at the left. Note that sometimes the error message appears on the line after the error. At the bottom of the window, you'll see "console" and "problems." The console window shows any printed output of the program. If you click on "problems" you'll see a list of the errors, and clicking on an item in the list will take you to the location of that error in the Java file so you can correct it.

  7. Modify the program: Now that you have Eclipse set up for CSE131, your task in this assignment is to modify the provided program so that it will drive the robot from CEC to your instructor's office. For more details, read the comment in the RobotController file just before the run method. As you work on your program, you may want to write a few statements and watch the program run, just to make sure you are on the right track. Since RobotController.java was the program most recently run, you can run it again simply by clicking the green arrow on the toolbar at the top. Each time it runs, you should see the results of your most recent modifications. Also, feel free to walk the route yourself, and stop by my office to say hello.
You now know the basic steps to create projects, as well as open, edit, compile, and run Java programs in Eclipse. You should also have a basic understanding of sequential execution and how to call methods on ojects. Please ask if you have questions about any of this.

Part II: Electronic Orientation

The CSE131 web pages at will be an important reference in CSE131, so it's worth spending a few minutes to get familiar with the site. In Eclipse, open the provided file "CSE131Trivia.txt" (under lab0). It contains questions that call your attention to a few administrative details you should know about CSE131. Using the Eclipse editor, fill in the answers to the questions using the information on the CSE131 web site.

What To Turn In:

Follow these submission instructions to turn in the following files and demonstrate your running program for a TA.
  1. cover-page.txt -- Be sure to fill out the provided file completely.
  2. RobotController.java -- Be sure to complete the header information at the top of the file (name, etc.).
  3. CSE131Trivia.txt -- With your answers to the trivia questions.
Note: Lab 0 and Lab 1 are due on the same day, so you will be doing both demos at the same time.