|
Computer Science 211 Data Structures Mount Holyoke College Fall 2009
|
|
Java and Unix on the Kendade 307 Macs
This is the repository for information about how to do the things you
need to do to use the Macs in Kendade 307 to complete your lab
assignments for Data Structures.
Mac Basics
- To open a terminal window, open a Finder window (click on the
background, then hit Apple-n), then click on Applications,
then Utilities, then on the Terminal program's icon. You
will likely use terminal windows often enough that you will want it
in your Dock at the bottom of the screen. To do this, drag the
Terminal icon into the Dock.
- To navigate to the folder of course shared materials, open a
terminal window and type
cd ~jteresco/shared/cs211
then open a Finder window in that folder by typing
open .
You should see three folders. eg contains the textbook's
examples. examples contains my examples from class. src
contains the source code for the structure package.
You may navigate around in these folders, and copy these to your own
folders by dragging and dropping.
Running Java Programs at the Command Line
- First, set up your account to access the structure package. You
will only need to do this once.
- Open a terminal window.
- Edit the file .bashrc in your home folder:
emacs .bashrc
At the end of this file, add the line
export CLASSPATH=.:/home/jteresco/shared/cs211/bailey.jar
- Close this terminal window and open a fresh one.
- Open a terminal window and navigate to the directory (folder)
that contains your program.
To compile a program, if it's in the file SnowStorm.java, you
would enter:
javac SnowStorm.java
And if SnowStorm contains the main method you wish to
execute, you run the program with:
java SnowStorm
If your program expects command-line parameters, you specify them
after the class name on the above command. For example:
java SnowStorm 2feetofpowder
Running Java Programs in Eclipse
- You can launch Eclipse by opening a Finder window, choosing
Applications, then eclipse, then on the Eclipse
icon. You may wish to add the icon for Eclipse to your Dock.
- The first time you start Eclipse, it will ask you to choose a
workspace. You may use the default path that Eclipse provides.
- To set up to run an existing program (such as a class
example that you have copied to your home folder) within Eclipse:
- Select File, New, Java Project to start
configuration of a new Eclipse project.
- This will bring up a dialog box.
- Fill in an appropriate "Project name"
- Under "Contents", choose "Create project from
existing source" and then Browse to the folder that
contains the Java program
- Click the "Next>" button
- This will bring up a new dialog.
- Choose the "Libraries" tab
- Click the "Add External JARs" button
- Navigate to /home/jteresco/shared/cs211 and choose
bailey.jar, then click "Open"
- Click "Finish"
- To set up to develop a new program within Eclipse:
- Select File, New, Java Project to start
configuration of a new Eclipse project.
- This will bring up a dialog box.
- Fill in an appropriate "Project name"
- Under "Contents", choose "Create new project in workspace"
- Under "Project layout", choose "Use project folder as
root for sources and class files"
- Click the "Next>" button
- This will bring up a new dialog.
- Choose the "Libraries" tab
- Click the "Add External JARs" button
- Navigate to /home/jteresco/shared/cs211 and choose
bailey.jar, then click "Open"
- Click "Finish"
- Click on the name of your new project in the pane on the
left. You can now create new Java files with "File", "New",
"Class".
Creating a "tar" File for Submission
When we have multiple files to submit for an assignment, you will be
asked to submit a single "tar file" that contains all of the
required files. A tar file is like a "Zip file" from the Windows
world.
We create a tar file using the tar utility at the Unix command
line in a terminal window (such as the Mac's Terminal or the shell you
get when you use secure shell to connect to babyred).
Historically, the tar program was used to create tape archives, hence the name.
Until you get the hang of it, you'll want to be extra careful using
tar. Incorrect usage could wind up corrupting your files. So I
recommend the following steps:
- Create a new, temporary directory/folder. For example:
mkdir ~/lab2submit
- Copy all of the files you wish to include in your tar file to
that directory. For example, to include all of your Java source
code and a file lab2.txt from the directory where you developed
your programs (in this case,
~/cs211/lab2
):
cd ~/cs211/lab2
cp *.java lab2.txt ~/lab2submit
- Change directory into your temporary directory and create your
tar file. For example, this creates lab2.tar:
cd ~/lab2submit
tar cvf lab2.tar *.java lab2.txt
You should see a message from tar listing the files that are
being added to your archive.
The cvf parameter seems cryptic (and, yes, it is) but you can
remember it if you know what it stands for: c is for create, v indicates a verbose mode (and is optional),
and f says to create the file speficified by the next
command-line parameter, lab2.tar.
In any case, you should now have a tar file lab2.tar ready to
send as an email attachment to submit your work.
- However...it's always a good idea to make sure the tar file you
have created does in fact include the files you think it includes..
First, you can list the contents of your tar file to make sure it has
the files you expect. For example:
tar tvf lab2.tar
But better yet, you can extract your tar file into an empty directory
and make sure the files there are the ones you expect and that their
contents are correct. For example:
mkdir ~/lab2test
cd ~/lab2test
tar xvf ~/lab2submit/lab2.tar
Here, the x indicates extract. You should then have the
files from the tar file in your test directory.
- If all is well, remove your temporary folders and their contents
to keep your account tidy.