Lab 01, Esc101, 2004-05 Semester-II

Your first Java program


Policy on copying: Labs are meant for learning. Discussions for the purposes of understanding are encouraged -- you may ask your friends or the TA for explanations, etc. But ultimately you should do your work, and copying is strictly discouraged. Be sincere and honest to yourself, and report any dishonesty to your TA or instructor.


The goal of this lab is to familiarize yourself with the Java environment, and write your first Java program.

You first need to get familiar with some basic Unix (Linux) commands and operations. A detailed tutorial is given here. You don't need to know everything explained there, but pay attention to chapter 3. You need to know how to create and change directories.

Task:

Create a directory named "esc101-lab01" and change directory to it

Next, you need to know how to start using bluej

Task:

From the command line, type "bluej&"

This should start up the bluej environment. The first thing to do once you start it, is to create a new project.

Task:

Create a project with the name "Counter" in the "esc101-lab01"
directory you had created earlier

Task:

Create a new class named Counter and open it for editing by
"right-clicking" on it

You can look at the Counter.java we discussed in class here. You can copy the code onto your own "Counter" code.

Task:

Compile the class Counter

Task:

Create one or more "Counter" objects.  Try calling the various
methods.  Try choosing "Inspect".  What do you see?

You can add more methods to the Counter class.

Task:

Add a method "decrement" which will decrease the counter by one

Task (bonus):

Add a method called "average" which will return the average of the set
of numbers given to the counter so far (you may have to add another
object variable for doing this)

Bhaskaran Raman
Last modified: Sat Jan 1 18:08:41 PST 2005