CPSC 329 Software Development Fall 2026

CPSC 329 Lab 1: Eclipse Setup and Git Basics

This lab takes you through configuring your Eclipse environment for this course and getting started with using Git in Eclipse — you'll set up a project, create a local repository, and practice two core workflows typical for solo developers. It also introduces some useful features of Eclipse that you might not be aware of — but would like to be. Later labs will introduce more advanced Git usage and workflows suited for team development projects.

Collaboration and AI

Labs are for learning and practice — you may help and be helped by others when it comes to figuring out what to do, but in the end you need to understand and be able to do the things for yourself.

You may not use AI to figure out what to do or to do the task for you.

Due Date, Deliverables, and Handin

due Fri 9/4 at the start of class

To hand in your work:


Preliminaries

Linux

It is assumed that you have used Linux at HWS before and that you are familiar with accessing Linux, navigating the Linux desktop, and working with the Linux filesystem (including terms home directory and root directory, path notation, and tasks like browsing the filesystem, creating directories, and copying files). Be sure to ask if that's not the case and you encounter something unfamiliar.

Some notes:

Eclipse

It is also assumed that you have used Eclipse before and that you are familiar with terms like workspace, project, perspective, view and basic tasks like creating a new project and importing files. Be sure to ask if that's not the case and you encounter something unfamiliar.


Setup

Directory Layout

We'll be using the following directory layout, which keeps everything for this course together under the same top-level directory (~/cs329) but separates the Git spaces from Eclipse's.

    ~/cs329                         ← parent folder for all cs329 coursework
      +-- dev/                      ← parent folder for all your Git repositories
      |  +-- lab1/                  ← each project gets its own independent Git repository
      |       + .git/               ← the repository itself
      |       + .gitignore          ← identifies files to keep out of the repository
      |       + src/                ← Java source code (.java files)
      |       + bin/                ← Java build output (.class files) — never committed
      + workspace/                  ← Eclipse workspace (bookkeeping only, no files)
         + .metadata/               ← Eclipse's internal state — never committed
(These are filesystem operations, not something done from within Eclipse.)


Eclipse Setup

Selecting the Current Workspace

The first time you start Eclipse (or if you have used Eclipse before but have configured it to ask each time), you will be prompted to specify a workspace directory — choose the directory you created above. If you are only using Eclipse for this course (or want to default to the workspace for this course), you can check the "Use this as the default and do not ask again" box — otherwise Eclipse will prompt you for the directory every time it starts up. To change to a different workspace once Eclipse is running, go to "File"→"Switch Workspace".

If you are starting Eclipse for the first time with a new workspace, you may get a welcome screen. Close it to get to the workbench display.

Configuring Workspace Settings

One useful feature of an IDE is the ability of the IDE to handle some of the grunt work for you — Eclipse can auto-format your code to adhere to a particular whitespace convention and can auto-generate some standard code (such as class headers and getters and setters) and comments. Eclipse stores these settings with the workspace so you can use different configurations for different sets of projects. (This also means that you will need to repeat these configuration steps for any new workspace you create.)


Basic Workflow

Create the Project

In Eclipse, create a new project named lab1 but located within your dev directory instead of the Eclipse workspace:

Note: if the project shows up in the Package Explorer with the name dev instead of lab1, first verify (via the system File Browser) that the directory structure is OK — there should be a directory ~/cs329/dev/lab1 containing subdirectories src and bin — and then update Eclipse's internal project name: in the Package Explorer, right-click on the project name (dev) and choose Refactor→Rename... Type lab1 and click OK.

Write Some Code

Create a (very) simple counter program that just prints out a static value:

Create the Local Repository

So far you just have a normal Eclipse project stored outside the workspace directory hierarchy. Time to get Git involved and create the repository!

Creating a new repository from an existing project is known as sharing the project. Eclipse's Git plugin (EGit) unfortunately has a well-known quirk when it comes to creating repositories with certain directory structures so don't use the straightforward right-click on the project then Team->Share Project... approach. Instead:

This creates the .git folder and a default .gitignore file within the project folder. Verify this by visiting ~/cs329/dev/lab1 in the system File Browser — you'll need to turn on "show hidden files" (View→Show Hidden Files) to be able to see things whose names start with ..

Back in Eclipse, you should see the lab1 repository in the Git Repositories view — the project folder and its contents will be under "Working Tree". (This is Git's working area.) You should also seem some additional decorations in the Project Explorer view — [lab1 main] is displayed after the project name, indicating what branch the current working copy is associated with, and other icons (mostly with question marks) provide information about each file's status. Keep an eye on those icons as you carry out various steps below to pick up on their meanings.

Set Up .gitignore

Only source code and other files that should be shared belong in a repository — generated files (such as compiled .class files) and configuration specific to a particular local environment (such as Eclipse's metadata files) do not belong in a repository. The .gitignore file provides a place to configure these exclusions so you don't have to keep avoiding them with every commit.

A default .gitignore was (probably) created as part of the previous step. If you don't see it in the Package Explorer view:

Now update it:

Make sure there aren't any spaces at the beginning of any of the lines. Starting with / means that the path is interpreted relative to the project root — only the bin directory at the top level of the project will match in this case, not other bin directories farther down in the hierarchy.

The First Commit

Recall that there are two steps in creating a snapshot: staging the changes that belong in the new snapshot and then saving the snapshot to the repository.

Edit, Checkpoint, Repeat

The core solo developer workflow is the basic loop: edit, checkpoint, and repeat.

Edit:

Checkpoint:

Repeat:

Other Useful Actions

Viewing history and snapshot diffs:

Document your progress so far:

Undoing/reverting:

To try this out:

At this point you should be back to the "Count: 1" program with only one snapshot in the history.

Branch, Edit, Checkpoint, Merge

Branches let you try something — a new feature, a risky refactor — without touching your working main line until you are sure the new changes are good.

Create a branch:

Edit and checkpoint on this branch:

The loop has been successfully implemented, so this feature is ready to be incorporated into the main line. Switch back to the main line, then merge in the feature branch:

If there are no conflicting changes (which should be the case here), Eclipse auto-merges everything and main now contains the reset feature.

Document your progress so far:

Resolving Conflicts

Conflicts can arise if there are changes to the line being merged into after the branch was created. If this happens, Eclipse marks the file as conflicted in the Package Explorer and lets you resolve the problems manually.

First, try to set up a situation where conflicts arise. The idea here is to reset the main line to the point where the loop feature branched off, then make a change that overlaps with the changes implemented in the feature.

To resolve conflicts, double-click the file to open the merge editor, which shows the two versions side by side. Pick the correct lines (or edit manually). When you are done, save the file and then right-click the file in the Package Explorer and choose Add to Index to mark the conflict as resolved. Repeat until all of the conflicts are resolved, then commit to finalize the merge commit.

Document your progress so far:

Cleanup

Once merged, you can delete the feature branch if you don't need it anymore: first switch the working area away from it if needed, then in the Git Repositories view, expand Branches→Local, right-click the branch to delete, and choose Delete Branch.


Eclipse Skills

The rest of this lab is an introduction to Eclipse — some things are basic procedures that you likely already know (and already had to do earlier in this lab) and some things are useful features you might not have seen. You are encouraged to read through it, carrying out and experimenting with any new features so that you become familiar with them. (You might need to work through some earlier steps to have the proper setup for a later task.) It is optional — only the setup and Git material above is required for completion of the lab.

Importing Files

Sometimes you'll want to include already-existing code in your project. To do this, you must import a resource:

Specify the destination where the imported files will be placed:

Specify what to import: (in this case, files from the file system)

Check the destination location:

Complete the process:

If you are successful, you'll now see the five files listed under your project in the "Package Explorer" tab. You may need to expand the "src" and "(default package)" items — make sure that the files end up under "(default package)" and not at some other level in the directory structure. Importing files like this copies them to your project directory — any changes you make will not affect the original copy.

Error Messages and Quick Fix

You may notice that some of the files have a little red X icon next to them in the Package Explorer.

Ever helpful, Eclipse warns you about potential problems and syntax errors — the little red X indicates errors while yellow ! icons are warnings. Errors and warnings are noted in multiple places: icons in the Package Explorer show files containing errors and packages/directories/projects containing files with errors; icons on the left side of the editor flag individual lines of code with problems; red and yellow boxes on the right side of the editor window show the location of problems within the whole file; icons in the "Outline" tab on the right show classes, methods, and variables with errors; and the "Problems" tab at the bottom lists information about the errors.

You can double-click on an error in the "Problems" tab or single-click on the red/yellow box on the right side of the editor window to go that error.

Eclipse will provide suggestions about how to fix the problem, and even carry out the fix for you.

You should have a new (but empty) class Guitar, and the first error in FindGuitarTester should have gone away (though there are now new errors).

Important: Eclipse is often right about the cause of the problem — but sometimes it isn't. Don't just always choose the first fix, or assume that the correct fix must be one of the choices! Make sure you understand what the problem is and what the fixes are that Eclipse is suggesting before selecting one.

Auto-Generating Code

To fix the remaining errors, it is necessary to implement the Guitar class.

Now, we need a constructor to initialize all the instance variables. You could type it by hand, or you can get Eclipse to do it for you:

Voilà! A complete constructor, except for needing to fill in the comments. (You can skip that for this lab.)

Next, we need getters for each instance variable and a setter for the price. Again, you could type them by hand, but why?

Whee, instant getters and setters! You can again skip filling in the comments.

Creating New Files

The guitar store is expanding, and would like to also sell mandolins.

First, create a new class:

Now, implement the class:

Auto Formatting

While you now have complete Guitar and Mandolin classes, the formatting may be a bit messy. Eclipse can fix this for you, so there's no excuse for handing in poorly formatted code.

Running the Program

At this point there shouldn't be any more errors in the program, so it is time to run it.

You should see the program's output below the editor tab — two guitars should match Erin's specifications.


Useful Features

Cleaning Up

Even properly formatted, Guitar and Mandolin may be a bit disorganized. To sort the elements of the class (instance variables and methods):

Note that all of the instance variables are now at the beginning of the file, and the variables and methods have been sorted in alphabetical order.

Renaming Things

Sometimes you need to change the name of something — a project, a package, a class, a method, a variable... This often involves a lot of search-and-replace while you hope you don't miss a spot — or you just decide the original name wasn't so bad after all. Eclipse makes renaming easy so there's no excuse to stick with poor naming choices.

In the example program, the name Type for the guitar type enumerated type is not the best because "Type" is pretty generic and doesn't give any clues as to what it is the type of. "GuitarType" is a more descriptive name, particularly when there may be other kinds of instruments with their own types.

Eclipse gives you control over how extensive the renaming changes are. The default is to just update references, but you can also update related usages (such as getters/setters when an instance variable name is changed, or some variable names when a class name is changed) and places where the name is used in comments and strings.

Let's get a better idea of what can be updated:

The next dialog box shows all the similarly named variables and methods that will be updated. You can review the choices and uncheck any that you want to leave alone.

The next dialog box shows all the changes that will be made. You can review the choices and uncheck any that you want to leave alone.

Observe the results in the now-renamed GuitarType class - even the reference to Type in the constructor's comments has been updated. Also note that all other references to Type have been updated e.g. in Guitar.

More Refactoring

"Refactoring" refers to changing a program's implementation without changing its functionality. Renaming elements is one type of refactoring; Eclipse can help in other situations as well.

Guitar and Mandolin are awfully similar — a better design might be to have an Instrument class with all of the properties common to both, and have Guitar and Mandolin extend Instrument.

Review what happened — look over Guitar and Mandolin and the new Instrument class. Eclipse did a pretty good job, but there's one other change that should be made — Instrument should have (only) a constructor which initializes its instance variables.

A couple of errors have now appeared, because the Guitar and Mandolin constructors made use of the default constructor in Instrument.

You can fix Mandolin in the same way, or try another approach:

There should be no more errors, and running the program should produce the same results as before.

Locating Declarations

Finding where a variable, method, or class is defined is not usually all that difficult — but it still can get tricky in a large project with lots of packages, and hunting down a method can involve first hunting down the type of the variable it is invoked on. Fortunately Eclipse can do it for you!

So, imagine that you are reading through the main program for this inventory software, and you come across something that you want to know more about...

The results are displayed in the "Search" tab below the editor showing your code. (It's probably no great surprise that this method is in the Instrument class since it was part of what was common to both Guitar and Mandolin.)

References

It is much harder to locate all the places in your code where a particular class, method, or even variable is used. Once again, Eclipse comes to the rescue.

This time you're reading through the main program and you want to know where else getBackWood is used.

Once again, the results are displayed in the "Search" tab below the editor showing your code. You can double-click on the desired entry in the "Search" tab to go to the location of a particular reference.

Exploring

Eclipse is a powerful tool, and does much more than has been described so far or that will be covered in this course. Feel free to explore and to experiment. A few things of particular interest: