In this class, we will be using a combination of text editor and the
command line java compiler, javac. You may use any
text editor you like, but the official "supported" text editor for this
class is NEdit. Our default OS will be Linux. You are free to install
the proper tools on your own PC, but your
programs MUST compile and run on the standard lab Linux setup.
The lab computers are already set up with all of the software that
you will need to create, compile, and run your programs. The following
is a brief tutorial for setting up a similar programming environment
on your home computer.
Note that I cannot officially support any setups outside of the
lab, although I will try to answer questions whenever possible.
Linux
You will need to install NEdit
(or, alternately, use your favorite text editor like emacs or vi) and
the Java SDK. We will be using version J2SE 1.4.2_01. Here is the
link to the Downloads page for this release. It is important that you
download the SDK (Software Development Kit), NOT the JRE (Java Runtime
Environment)! (The SDK comes with the JRE; you will
need the SDK to compile your programs.) Installation instructions are
also linked on this page.
Make sure that you put the Java executables (javac and
java) in your path. There are several ways to do
this:
- Copy the executables
javac and java
into /usr/local/bin. Or,
- Set your executable path (PATH) so that it contains the directory
where you installed Java:
- Figure out where java was installed on your system. To do so,
type at the command prompt
which java
- Figure out what shell you are using. To do so, type at the
command prompt
echo $SHELL
- If you are running the bash shell (
/bin/bash), open
up the file .bash_profile (note the leading period) in
your home directory. You should see a line that starts with
PATH=... Let's say that java is installed in the
directory /usr/local/j2sdk1.4.2_01/bin. At the end of
this line, type (NO SPACES!)
:/usr/local/j2sdk1.4.2_01/bin
Be sure to include the colon! Then either log out and log back in,
or type at the command prompt
source $HOME/.bash_profile
- If you are running a c-shell, like csh or tcsh, open the file
.cshrc (note the leading period) in your home directory,
or create it if it does not exist. Let's say that java is installed in the
directory /usr/local/j2sdk1.4.2_01/bin.
Type the following line anywhere in the file:
set path = ( /usr/local/j2sdk1.4.2_01/bin $path )
Note the spaces! Then either log out and log back in, or type at the
command prompt
source ~/.cshrc
Assuming you have installed everything correctly, usage will be the
same as it is for the lab computers.
Windows
It is recommended that you use Notepad (or whatever your favorite
text editor is) to write your programs. Make sure that you save your
files as text, but not with an automatic extension; otherwise, your
class files will most likely be written to a file that ends in
.txt.
Alternately, you can
install NEdit for Windows, but the installation is a bit complicated.
This page (scroll
down a bit) has additional info if you want to attempt to install
NEdit.
You will also need to install the Java SDK. Here is the
link to the Downloads page for this release. It is important that you
download the SDK (Software Development Kit), NOT the JRE (Java Runtime
Environment)! (The SDK comes with the JRE; you will
need the SDK to compile your programs.) Installation instructions are
also linked on this page.
You will probably want to create a directory to store all of your
Java programs, e.g. C:/JavaFiles.
To compile and run programs, open a Command Prompt window, and
cd to the directory where your program file(s) live(s).
Then type javac and/or java as described for
the lab computers.
If you try to compile or run a Java program, and you get an error
like NoClassDefFoundException or Can't find
class, you may need to set your CLASSPATH environment variable
(i.e., tell Java where to find your class files). This
page explains how to set your classpath in Windows.
If you try to compile or run a Java program, and you get an error
like javac: Command not found or java: Command
not found, you need to set your execution path (PATH). To do
so, go to Control Panel, select System, and find the button that says
"environment variables". You should be able to find the PATH here and
append the path to where Java is installed.
Mac
It is suggested that you use your favorite text editor on Mac to
write your programs. Again, make sure that you do not automatically
save your files with an extension, or else your programs will most
likely save with a .txt extension. Also, make sure that
your files save as plain text and not RTF.
There
is a port of Nedit to OSX. Here (scroll down) are
the details if you would like to install it on your own machine.
OSX already has the Java SDK installed, so everything should just
work. If you are running Mac OS 9, download the MRJ SDK 2.2 from this page.
To compile and run programs, open a Command Prompt window, and
cd to the directory where your program file(s) live(s).
Assuming you have installed everything correctly, usage will be the
same as it is for the lab computers.