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):
k03xx01). Note:
if there isn't an M: Drive associated with your Knet ID under
"My Computer,", talk to your instructor immediately!
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.
main
method to print a simple message, as in the following example:
public static void main(String[] args)
{
System.out.println("Hello, world.");
}
Compile and run the modified program. Your message should
appear in a new window.
Print your modified files. When you are done making your modifications, print the project README file and the Java source code and class documentation for the TrivialProgramClass class (3 print-outs). You will find the Print option under the Class menu. Remember that you can go back and forth between the Java source code and the class documentation for a class using the pull-down menu in the upper-right corner of the editor window.
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.
main method for the
TemplateOfClassWithMainMethod class different from the
main method for the TrivialProgramClass class?
public class ClassName)
correspond to the contents of its class documentation
page (the page you see when you switch from
Implementation to Interface
in the pull-down menu in the upper-right corner of the editor
window)?
How does the use of the HTML <br> (line-break) tag
affect the look of the class documentation
page? What effect do
the Javadoc @author and @version tags have?
Print your answers to the Analysis Questions above.
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.
main
method to start the program.main.
As a quick way to become familiar with what the Aquarium simulation
program does, compile and run the program using the main
method in the AquaSimApplication class. You should see a
window appear with a Start button and some instructions at the
bottom. This is the program's graphical user interface.
When you press the Start button, you should see a
white fish drawn on a blue background (the aquarium). That is
all the program does for now. Close the graphical user
interface window.
main. To run the Aquarium simulation
program using BlueJ and without a main method will take
a number of steps.
main method, or any other dimensions. You
will also have an opportunity to set the name of the instance
(for example, "aqua") or use the default ("aquarium1"). Once
you have constructed the aquarium object, a red icon for it will
appear in the object bench, the window area below the
project diagram and control panel. Note that you will not see
a display of an aquarium with a blue background, because you
have not yet created a graphical user interface and display.
Print your answers to the Analysis Questions above.
Hand in your modified files and Analysis Question answers from this lab.
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.
main method in your
new class. Update the project README file (the icon in
the upper-left corner of the project diagram) and the javadoc
comments in the class to reflect the changes you make.
If you wish to work on your own computer: Copy your program to your own computer (if it is on the campus network) or to a USB drive. If you do not have BlueJ on your own computer, you can download it from www.bluej.org. It is free, open source software, and quite easy to install.
Due at the beginning of Lab 2: Print the project README file and the Java source code and javadoc class docmentation for the class (3 files altogether) , and hand them in at the beginning of Lab 2.