CS 239 Advanced Programming
Lab239-L01A: Introducing a new IDE, Eclipse

Objectives

The students will be able to:

Background     

In CS 139, while we don't specify which editor a student must use, we generally demo and introduce simple editing tools, like JGrasp and DrJava. In most working environments, you will use a more fully featured IDE which will provide you with tools and support that the simpler editors do not. In this lab, you will explore Eclipse. If you already use the Eclipse editor, this lab, may provide you with more information, or feel free to use the alternate NetBeans lab.

New Terms

Project
All Eclipse applications are built as a project. Each lab and each PA that you do this semester should be in its own project and each project will have its own folder.

Materials Used

 


Part 1 - YouTube Video

  1. Watch the YouTube video which provides an overview of Eclipse. You can open Eclipse and follow along if you like. http://www.youtube.com/watch?v=23tAK5zdQ9c

Part 2 - Make your own Hello World using the Eclipse tutorial

  1. If you have not done so already, open Eclipse. At the Workspace prompt, fill in your workspace. This could be a folder on a thumb drive or your desktop.
  2. Choose the tutorials icon. (Pen and green checkbox).
  3. Choose Create a Hello World application.
  4. Follow the steps in the tutorial. Be sure to see how the automatic syntax checking works by introducing some bugs. Also explore the autofill options (showing the list of available members of an object).

Part 3 - Import preferences
Eclipse allows you to modify the rules that control nearly every aspect of the development environment. You can access these rules by choosing "Preferences" from the menu at the top of the screen. Rules for formatting are included under "Java". A predefined preferences file that incorporates the stylistic standards for CS239 is included in the attached Preferences.epf file. rules can be modified t
  1. Download the file "Preferences.epf" to your Desktop (right-click and choose "Save a").
  2. Import this file by choosing "File" and then "Import" from the menu at the top of the screen.
  3. Open up the "General" tab in the "Import" window.
  4. Select the "Preferences" icon, and then press the "Next" button.
  5. Press the "Browse" button to locate the Preferences.epf file that you downloaded.
  6. Make sure that the "Import all" checkbox is checked. Then press the "Finish" button.
  7. Once you have successfully imported the new preferences file, create a new Hello World application, leaving the one you entered earlier intact. (If you called the first program "HelloWorld", you can call this one "HelloWorld01" for example).
  8. What differences do you see in the way that the two programs are formatted?
Since the preferences are not preserved from one day to the next in the lab computers, you will need to import this file each time you use one of the computers in the lab. If you are using this on your own computer, though, you will only need to do this once.

Part 4 - Import other .java files into a project

Next, you will practice downloading an existing java source code file and importing it into your project.
  1. Download the file "ArrayPlay.java" to your Desktop.
  2. Drag the file into the "src" section of your project. It's as easy as that!!
  3. Note: ArrayPlay.java requires another file. We will deal with that file in the next section. Notice the red X's if you open this file in the editor.
  4. Alternately, you can import this file from the "File" menu as well. We'll leave this up to you to figure out.

 


Part 5 - Adding .class files into a project

Sometimes you want to use a class file that has already been built into your project. This part of the lab will let you explore that feature.

  1. Download the Die.class file onto your Desktop. This is the class that is missing from the ArrayPlay application.
  2. Go to Project/Properties and click on JavaBuildPath.
  3. Click on Libraries.
  4. Click on Add Class Folder.
  5. Click on New Folder. Give your folder a name such as "classes".
  6. Press Okay. You will see a new section in the Package Explorer window called Referenced Libraries and you should see your new folder beneath it.
  7. In the Eclipse window, drag and drop your Die.class file into the folder you just created.
  8. You should see the errors in ArrayPlay go away.

Part 6 - JUnit testing

JUnit testing is supported by Eclipse. If you recall, you build a test file for each class in an application to test each method of the application. For those in CS 139 last semester, you built the test files to test your code and also to "prove" to WebCAT that you had tested all lines and branches of your code (code coverage). For this part of the lab, we will use Eclipse to build JUnit tests for ArrayPlay.

  1. To create a new JUnit test for a particular file in the project, right click on the name of the file in the src list and choose New/JUnit Test Case.
  2. Click on the JUnit 4 Test radio button.
  3. The name of the file defaults to the name of the active class with Test appended (ArrayPlayTest).
  4. Click on Generate comments, and then click on Next.
  5. From the list of methods of the ArrayPlay class, click on the box beside each of the two methods in the class. Don't worry about the Object class below it.
  6. Click Finish.
  7. You may have a window pop up to say that you don't have JUnit4 in your class path. But it will add it for you automatically, so click okay.
  8. The ArrayPlayTest file opens in the editor. You may now add test cases to test the ArrayPlay class.
    1. NOTE: The order of the Die rolls for the testCountRolls method for a Die object created with a seed of 123456 is 6,2,2,5,2,4,5,1,2,4. (The method just rolls 10 times.)

Part 7 - Remember CodingBat?

If you have not already done so (last semester) go to CodingBat.com and set up an account. Once you have an account, you can add your instructor to your work by going to Prefs and then adding your teacher's e-mail address (either harrisnl@jmu.edu or nortonml@jmu.edu). If you have your 139 teacher listed, you can remove them now.

Do the problem in Warm-Up 2 called frontTimes (http://codingbat.com/prob/p101475).


last updated 01/06/13 - nlh