Lab Exercise #1
Wednesday, Sep. 3, 2003
You must complete this
laboratory in order to proceed with the course. If, for any reason, you
cannot finish it during the lab session, you must finish it by 5 PM, Friday,
September 5, 2003.
Objectives: The purpose of this lab is to give you some
practice
in organizing and manipulating your Unix file system, and to get ready
to use the program distribution that the course textbook provides. In
working
with Java beyond an introductory course, it is really important to
understand
directory structures, because Java compilers require a
correspondence
between your package/class structure and your directory structure.
Step 1: Make sure you have both GW and SEAS accounts.
You will need a SEAS computer account to do the work in this course. On
your lab PC, open an SSH window and log in to the SEAS server, hobbes.seas.gwu.edu. If you
can't log in, find out why and do whatever you must do so that you can
log in to hobbes.
Step 2: Bring your filesystem up to the CSci 53 state.
- If you took CSci 53 last spring,
you have two things to do in this step
- complete the survey form
that's in info/survey.txt.
- go to your csci53 directory and erase any *.class files that are left
there. This will free up some space. Don't erase your CSci 53 source
code, only the class files! Type
rm
*.class
- If you did not take CSci 53
last spring,
- complete the first CSci 53 lab
exercise, which sets up your filesystem, gives you links to the proper
Java compiler, and gives you links to the programs from the Lewis &
Loftus textbook. This lab is on the web at
www.seas.gwu.edu/~csci53/fall03/53f03lab1.html.
At the end of this step, you will have, in your home directory,
- a directory csci53
- a link (shortcut) csci53/programs53,
which points to the Lewis & Loftus programs
- a subdirectory, csci53/cs1,
which contains a Java source file Keyboard.java.
This Java class, written by Lewis & Loftus, is what we will often
use to get interactive input from the keyboard.
- a few programs in csci53,
which you've copied and compiled just to get the feel of the compiler.
- any source files left over from CSci 53.
Step 3: Set up your CSci 133 directory structure.
There is no special setup script for this course, because it's
useful
for you to understand the details of your file system by setting up
some
of it yourself.
- First modify your .kshrc file to let the Java compiler know
how
to find
all your Java files.
The .kshrc file (short for "Korn Shell startup file")
contains
commands that are executed each time you enter a copy of the shell --
when
you log in, when you call jcompile, etc. Move to your
top-level
directory, and bring .kshrc into your editor. It should
contain
the line . ~csjava/csci53.profile. Immediately below this
line,
add the line
export CLASSPATH=~:~/csci53:~/csci133:$CLASSPATH
which extends the path the compiler should take in looking for Java
sources and class files. In Unix, the symbol ~ ("tilde") refers to the
home directory.
- Now learn some useful variants of the Unix ls
command.
Move to your top-level directory, and type each of the following,
noting
down a description of what each one displays. Note that these are lower
case L's and not numeral 1's.
ls -a
ls -l
ls -al
ls -alR
ls -R
The last variant will be very useful in this lab. Each time this
handout
says "list your file system", use the last command above.
- Now make a directory structure for the course.
In your top-level directory, type
mkdir csci133
and then
mkdir
csci133/mbf
mkdir
csci133/cs1
The first directory is where you'll do much of your work; the mbf
subdirectory is where you'll store the reusable classes Prof. Feldman
will provide and the cs1 subdirectory holds the Lewis &
Loftus
class cs1.Keyboard, which provides simple keyboard input
methods.
- Now set up a "shortcut" to the
CSci 133 textbook program
library.
Move into your csci133 directory, then type
ln -s ~csjava/programs133
which makes the program library visible to you. In CSci 53, all the
programs were in one directory (except for Keyboard). In this course,
the
programs are distributed into the top-level directory and several
subdirectories.
- Now copy a few files from the distribution into your own
structure.
Type
cp programs133/mbf/Screen.java mbf
cp programs133/ShowInputLoop.java .
cp
programs133/cs1/Keyboard.java cs1
cp programs133/Smiley.java .
Examine mbf/Screen.java with vi and note that the first
actual
code line
reads package mbf;
Examine cs1/Keyboard.java
with vi and note that the first actual
code line
reads package cs1;
The
subdirectory structure matches the package structure.
Java
compilers REQUIRE this! In this course, whenever you copy a file from
the course distribution, you must put it into the equivalent location
in your own file
system, otherwise you will surely get compilation errors!
- Now compile the two
reusable class files.
Type
jcompile mbf/Screen.java
jcompile cs1/Keyboard.java
You should get successful compilation messages. The listing and class
files are in that same subdirectory - try listing that subdirectory to
be sure. Also move down into the subdirectory and back.
- Now compile and run two applications that use the class
files:
Type
jcompile
ShowInputLoop.java
jrun
ShowInputLoop
jcompile Smiley.java
jrun Smiley
- Now read the two applications, and the documentation for
the two classes, carefully. You'll be using them.
- Congratulate yourself on getting through all this!
(end of lab)