Computer Science 132
Computer Science II

Dickinson College
Spring Semester 2010
Grant Braught

COMP132 How-To List

Eclipse

Command Line

SVN


Creating a new project in Eclipse

  1. Open the File menu and choose New.
  2. Choose Project... from the pop-up menu.
  3. In the New Project dialog, select Java Project and click Next >.
  4. Enter the name for your project in the Project Name box.
  5. Set the following options:
  6. Click Finish.

    A new project with the name that you specified will appear in the Package Explorer tab in the left part of the Eclipse window.

Opening a project in Eclipse

  1. Double click on the project's folder in the Package Explorer tab.
  2. Click Yes in the Question dialog asking about opening referenced projects.

Creating a new package in Eclipse

  1. Ensure that the project to which you want to add the package is open. See Opening a project.
  2. Right click on the src folder of the project and choose New.
  3. Select Package... from the pop-up menu.
  4. Enter the name of your package in the Name field of the New Java Package dialog.
  5. Click Finish.

    A new package with the name that you specified will appear within the project's src folder in the Package Explorer tab in the left part of the Eclipse window.

Creating a new class/interface in Eclipse

  1. Right click on the package to which you want to add the class or interface and choose New
  2. Select Class or Interface as appropriate.
  3. Enter the name of the new class or interface in the Name field of the dialog.
  4. Click Finish

    A new class (or interface) will appear within the package in the Package Explorer tab in the left part of the Eclipse window. An editor window will also open for the new class (or interface) with a stub implementation to be completed.

Running a Java program (i.e. main) in Eclipse

  1. Right click on the class containing the main method you wish to run.
  2. Select Run as and choose "Java Application" from the pop-up menu.

    The program will execute and any output generated will appear in the Console tab at the bottom of the Eclipse window.

    NOTE: Pressing Shift-Apple-F11 will re-run the last executed program.

Running a Java program with command line arguments in Eclipse

  1. Right click on the class containing the main method you wish to run.
  2. Select Run Configurations....
  3. Open the (x)= Arguments tab.
  4. Type the command line arguments into the Program arguments box.
  5. Click Run

    The program will execute given the command line arguments that you entered. Any output generated will appear in the Console tab at the bottom of the Eclipse window.

    NOTE: Once the command line arguments have been entered they will continue to be used each time the program is run. Thus, subsequent runs can be done using the simpler method for running a program or by using the Shift-Apple-F11 shortcut. To change the command line arguments repeat the process given above.

Creating a new JUnit Test Case in Eclipse

  1. Right click on the class that you wish to test and choose New.
  2. Select JUnit Test Case from the pop-up menu.
  3. Choose the New JUnit 4 test radio button at the top of the New JUnit Test Case dialog.
  4. Click on Finish.
  5. If this is the first test case added to the project a second dialog box will appear stating Junit 4 is not on the build path. Click OK

    A new class will appear beneath the class being tested in the Package Explorer tab in the left part of the Eclipse window. The name of the new class will be the name of the class being tested with "Test" appended to the end. An editor window will also open for the new test class with a stub implementation to be completed.

  6. Add the following lines to the top of the new test class just below the package statement:

Creating a new JUnit test method

  1. Bring the editor window for the test class to which you wish to add to the front.
  2. Create a stub for your test method as shown here:
  3. Change the name of the method from testSomething to be descriptive of what you are testing.
  4. Replace the fail assertion in the body of the test method with your test.

    The assertions that can be used in a JUnit test include:

Running JUnit Test Cases in Eclipse

  1. Right click the JUnit Test Case (or package, or project) containing the tests you want to run.
  2. Choose Run As and select JUnit Test from the pop-up menu.

    All of the test methods in the Test Case (or package, or project) that you selected will be executed. The JUnit tab will become active on the left side of the Eclipse window and will show you your test results.

  3. Click on any failed test to see the message from the failed assertion.
  4. Double click on any failed test to see the test method containing the assertion that failed.

Opening a terminal

  1. Click on the Terminal Icon on the dock at the bottom of the screen.

    If a terminal icon does not appear on the dock:

  1. Click on the Smiling Mac Face on the dock.
  2. Click on Applications on the left part of the finder window.
  3. Scroll to the bottom and open Utilites
  4. Scroll to the bottom and double click the Terminal.app icon.

    A terminal window will appear on the screen. The prompt will contain a ~ followed by your username (e.g. ~ braught$). This indicates that the current working directory is your home directory.

Listing files in a terminal

  1. Type ls at the prompt in the terminal window.
  2. Press the return key.

    A list of the files and directories contained in the current working directory will be displayed.

Changing directories in a terminal

  1. Type cd followed by a space followed by the directory name at the prompt in the terminal window.
  2. Press the return key.

    NOTE: the directory name entered following cd must be contained in the current working directory.

    NOTE: to move upward out of a directory use cd .. (cd followed by a space, followed by two periods).

    The prompt in the terminal will change to reflect the new current working directory. For example:

Running a Java program in a terminal

Setting up the SVN Repository

  1. Open Eclipse
  2. From the Window menu select Open Perspective and choose Other... from the pop-up menu.
  3. Select SVN Repository Exploring and click OK
  4. Right click in the SVN Repositories Panel on the left side of the Eclipse window.
  5. Select New and choose Repository Location... from the pop-up menu.
  6. Enter the following information in the New Repository Location dialog box:
  7. Click the Finish button.

Getting the Sample Code from the SVN Repository

  1. Open Eclipse
  2. From the Window menu select Open Perspective and choose Other... from the pop-up menu.
  3. Select SVN Repository Exploring and click OK
  4. Expand the COMP132 folder
  5. Expand the COMP132S10 folder
  6. Right click on the 132SampleCode folder and choose Check Out from the pop-up menu.
  7. From the Window menu select Open Perspective and choose Java... from the pop-up menu.

    The 132SampleCode project will now appear in the Package Explorer tab at the left of the Eclipse window.

Updating the Sample Code from the SVN Repository

  1. Right click on the 132SampleCode project in the Package Explorer tab.
  2. Select Team and choose Update from the pop-up menu.

Getting the Labs Project from the SVN Repository

  1. From the Window menu select Open Perspective and choose Other... from the pop-up menu.
  2. Select SVN Repository Exploring and click OK
  3. Expand the COMP132 folder
  4. Expand the COMP132S10 folder
  5. Expand the Students folder
  6. Expand the folder with your username
  7. Right click on the 132Labs folder and choose Check Out from the pop-up menu.
  8. From the Window menu select Open Perspective and choose Java... from the pop-up menu.

    The 132Labs project will now appear in the Package Explorer tab at the left of the Eclipse window.

Updating the Labs Project from the SVN Repository

  1. Right click on the 132Labs project in the Package Explorer tab.
  2. Select Team and choose Update from the pop-up menu.

Turning in the Labs Project to the SVN Repository

  1. Right click on the 132Labs project in the Package Explorer tab.
  2. Select Team and choose Commit... from the pop-up menu.
  3. Enter the lab number, your name and the name of your partner in the Comment box.
  4. Click OK.