CS 110: Introduction to Programming in Java

Kalamazoo College

Spring 2008

Lab: Getting Started with Eclipse


Exercise 1: Creating a Folder for your CS 110 work

It makes sense to keep your CS 110 programs together in a single place, separate from other documents or materials you may have from other classes.

  1. Double-click on the "My Computer" icon on the desktop.
  2. Double-click on the folder associated with your ID (e.g., k03xx01).  Note: if there isn't an icon for your server directory under "My Computer," you will need to follow the following instructions to get to Dragon the long way. If you need to use this convoluted way to get to Dragon now, chances are you will need to use it repeatedly throughout this course, which is why it is getting so much prominence here.
    Getting to Dragon the long way... (only if necessary)
    • Click on "My Network Places" on the Start menu
    • In the "Other Places" box, click on "Entire Network"
    • Double-click on Microsoft Windows Network
    • Double-click on Knet
    • You will see many machines listed; double-click on Dragon
    • In this case, since you are looking for your own space on the network server, double-click on Students and then on the folder with your own Knet ID (e.g., k03xx01).  In other cases, when you are looking for CS 110 materials, from Dragon you will double-click on the cls_compsci folder.
  3. Create a new sub-folder named CS 110 (or something similar) in your folder. Throughout this course, you will be creating new sub-folders in this space.


Exercise 2: Creating a Program Using Eclipse

An object-oriented program is, as we learned in class, made up of a collection of classes.  Each class is stored in a separate file, where the name of the file is the name of the class with a .java extension.  Thus, a class called Aquarium must be in the file Aquarium.java.  We might have many classes in a program, and we might have many programs.  How do we keep track of which classes are part of which programs?

The Eclipse development environment uses the idea of a project to keep track of information about a program, such as which classes are part of the program, where the program's starting point is, and so on.  To run or modify a program using Eclipse, the first thing to do is to start up Eclipse and then create a new project or open an existing project to contain and keep track of our classes.

We also learned in class that a running program consists of objects invoking operations on other objects.  How, though, can we start an application when it doesn't have any objects yet to do any operations?  The answer is that at least one of the classes in an application must have a special operation called main.  (The definition of an operation in a class is called a method definition, so this operation is called a main method.)  A main method is not tied to any particular object, so the development environment (or whatever software is running the program) can invoke it, even though it doesn't have any objects yet.  The main method then constructs one or more objects and invokes operations on them.  They, in turn, may construct objects and invoke other methods, which is the essence of an object-oriented program.  To start a Java application, Eclipse looks through the project for a class that has a main method and invokes it. 

Let's start by creating a very simple program with a single class. To keep things simple, the only method we will create is a main method.


Exercise 3: Dragging Files from Dragon

Many of the labs and programming assignments in this course will involve modifying existing programs provided for you on the college's server called "Dragon."  For example, in the first few weeks of the course you will be developing an Aquarium program.  You will be writing all of the logic that actually runs the program, but we will provide graphics code that your program will use.  Thus, you will start by copying an existing program with the graphics code already in place, and then modify it.  The versions of all the CS 110 programs on Dragon will also include the necessary Eclipse project information for you to run the programs under Eclipse.

To run and modify the programs we provide on Dragon, you will first have to copy them to somewhere where you have the correct permissions, such as your directory on the campus server or your computer in your dorm room.  The directions below assume that you are working in a lab and want to copy.

  1. Bring up a window showing the files that you want to copy.
    1. Double-click on the "Knet" icon on the desktop.  In the Knet folder you will see a number of machines listed.  Double-click on Dragon.  [Note: If there isn't a Knet icon on the desktop, then you'll have to get to Dragon the long way outlined in the box at the beginning of this document.]
    2. Once you're in the Dragon folder, double-click on cls_compsci.  (This is where computer science classes have their Knet archives.)
    3. Double-click on cs110.
  2. Bring up a window showing the folder to which you want to copy the files.  For example, to copy the files to your directory on the campus server, do the following:
    1. Double-click on the "My Computer" icon on the desktop.
    2. Double-click on the folder associated with your ID (e.g., k03xx01).  [Note: if there isn't an icon for your server directory under "My Computer," follow the instructions above to get to Dragon the long way, and then double-click on the "students" folder and then on your own directory.]
  3. Drag the appropriate folder or files from the cs110 folder in one window to your own folder for this class in the other window. For this lab, drag the JavaMBSUsingEclipse folder.


Exercise 4: Opening and Running an Existing Program Using Eclipse

For this part of the lab, you will copy and run the Marine Biology Simulation program.


Exercise 5: Experimenting with the Marine Biology Simulation Program


Exercise 5: The Edit-Compile-Run Cycle

Now let's return to a project you were working on before, to add new functionality to it.  You will do this frequently in this course, since enhancing an existing program (editing, compiling, and testing existing files) is much more common than creating a completely new one.  In fact, since it is almost impossible to sit down and write a program absolutely correctly from scratch, even new programs are often created by modifying previous programs.


Exercise 6: Cleaning Up

Be sure to clean up the Eclipse workspace before you go, so that the next person to use the same machine does not see your files.  One at a time, choose each project and then select "Delete" under the "Edit" menu.  In the confirmation dialog box that appears, be sure that you check "Do not delete contents"!!!

Make sure that you saved your program to your directory on the campus server or a disk on your own network.  In addition, you may wish to save a backup copy in one of those two places, or on a USB drive.


When you complete the lab, you can start work on Programming Project #1 (due at the beginning of Lab 2).