Lab: Getting Started with BlueJ

BlueJ is a Java development environment; in other words, it is a software application that provides tools for reading, writing, compiling, and running Java programs. In this lab, you will create a folder for use in this course and learn how to use BlueJ to modify simple programs, run programs in two different ways, and create a program from scratch.


Exercise 1: Create 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 for other classes.

If you are working on K College computers (any computer that is part of Knet):

  1. Double-click on the "My Computer" icon on the desktop.
  2. Double-click on the M: Drive associated with your Knet ID (e.g., k03xx01).  Note: if there isn't an M: Drive associated with your Knet ID under "My Computer,", talk to your instructor immediately!
  3. Create a new folder named CS110 (or something similar) on your M: Drive. Throughout this course, you will be creating additional sub-folders in your CS110 folder (or whatever you chose to call it).


Exercise 2: Download and modify a trivial Java program.

An object-oriented program is, as we learned in class, made up of a collection of classes.  The Java code for 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, the Java code for a class called Aquarium must be in the file Aquarium.java.  In BlueJ, the classes for a program are all stored together in a folder. 

We also learned 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?  In Java, we can start an application by invoking a special "start-up" operation called main.  (Java operations are called methods, so this operation is called the main method.)  A main method is not tied to any particular object, so the BlueJ development environment (or Eclipse, or whatever software is running the program) can invoke the main method, even though the program doesn't have any objects yet.  The main method then constructs one or more objects and invokes methods on them.  They, in turn, may construct other objects and invoke other methods, which is the essence of an object-oriented program.

We will start by downloading a very simple program with a single class. To keep things simple, the only method this class has is a main method.


Exercise 3: Download and save class templates for future use.

When you create new projects and new classes in BlueJ, the development environment will provide you with some sample code and documentation in the project README file and in the classes.  The documentation conventions for this course, however, are slightly different from the documentation that is provided automatically.  The CS110Templates project contains a project README file and two sample classes with documentation corresponding to the conventions for this course.  One class contains a main method, while the other is a normal class with an instance variable, a constructor, and a method.  In future projects, you may find it useful to copy and paste the comments from these classes into new classes, and then edit them to reflect the actual behavior of the new classes.


Exercise 4: Look, Ma, no main!

Although stand-alone Java programs need a main method as a starting point, in BlueJ it is possible to construct objects from the icons in the project diagram and then invoke methods on those objects directly.  For this exercise, you will be working with a project that will simulate fish swimming around in an aquarium.


Exercise 5: Creating a new project (OR, Getting started on Programming Project #1).

In this exercise you will be creating a new project from scratch that will be similar to the TrivialJavaProgram project you worked with at the beginning of the lab.  This will be your first programming project, due in lab during Week 2.