In CS 117, CS 127, and some of our other courses, we use 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 these classes is jEdit. You are
free to install the proper tools on your own computer, 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 we cannot officially support any setups outside of the
lab, although we will try to answer questions whenever possible.
Note that the current version of Java is Java 6.0 (also known as
Java 1.6.0). This is the version that we have installed in the
department labs. There is no difference between Java 5.0 and Java 6.0
whatsoever that impacts our courses (the differences are very
obscure), so if you have Java 5.0 installed on our home computer,
there is no need to upgrade. Java 6.0 has not been released for the
Mac yet, so if you're using a Mac at home, you'll need to install Java
5.0. Regardless of what version you're running at home, you should
always make to test your code on department computers before
submitting.
Note that on the department machines, we have changed the default
options for jEdit slightly. See the very bottom of this page for a
list of the changes we have made to jEdit.
Linux
You will need to install jEdit
(or, alternately, use your favorite text editor like emacs or vi) and
the Java JDK. We will be using version J2SE 6.0 (also known as J2SE
1.6.0). Here is
the link to the Downloads page: choose "JDK 6 Update X" (where X
is the most recent update. It is important that you download the JDK
(Java Development Kit), NOT the JRE (Java Runtime Environment)! (The
JDK comes with the JRE; you will need the JDK 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/jdk1.6.0/bin
. At the end of
this line, type (NO SPACES!)
:/usr/local/jdk1.6.0/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/jdk1.6.0/bin
.
Type the following line anywhere in the file:
set path = ( /usr/local/jdk1.6.0/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.
Finally, once you have completed your work you will want to
transfer it to your department account so that you can test it there
before submitting. To do so, use the scp command:
scp [filename] [username]@prism.mathcs.carleton.edu:~
... and enter your Carleton password.
This connects to prism, which is one of our department
computers, and copies your file to your home directory.
If you actually want to connect to prism remotely to run
your code, do so by typing
ssh [username]@prism.mathcs.carleton.edu
... and enter your Carleton password. This will give you access as
if you were sitting in front of a terminal window here in the
department, but note that you will not have access to any kind of
graphics or images.
Windows
You can use Notepad if you like to write your programs, though you
will probably be happier in the long run if you install and use jEdit. If you do choose to use
Notepad, 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
.
Here is
the link to the Downloads page: choose "JDK 6 Update X" (where X
is the most recent update. It is important that you download the JDK
(Java Development Kit), NOT the JRE (Java Runtime Environment)! (The
JDK comes with the JRE; you will need the JDK 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.
Finally, once you have completed your work you will want to
transfer it to your department account so that you can test it there
before submitting. To do so, use the program WinSCP. After you have
installed the program, start it up, and enter
prism.mathcs.carleton.edu for the host name, and enter your
user name and password in the appropriate boxes. Click Login. Click
Yes to trust the host (if this question appears). You should then see
your local computer on the left side, and your home directory for our
department accounts on the right side. Drag and drop your files and
directory as appropriate to move them over.
If you actually want to connect to prism remotely to run
your code, do so with the program PuTTY.
When you start PuTTY, enter prism.mathcs.carleton.edu for the
Host Name, and click Open. This will give you access as if you were
sitting in front of a terminal window here in the department, but note
that you will not have access to any kind of graphics or images.
Mac
You can use any text editor that you like to write your
programs. We recommend, in particular, jEdit. If you use a different text
editor, make sure that you do not automatically save your files with
an extension, or else your programs might save with a
.txt
extension. Also, make sure that your files save as
plain text and not RTF.
OS X has Java automatically installed, but you may or may not have
Java 5.0: you might instead have an early version (such as Java
1.5). To check, open up the Terminal, and type java
-version. If you see something regarding 1.5, you're fine. If you
have an older version, you'll need to download the newest version of
Java (J2SE 5.0) from this page.
This doesn't replace the old version of Java, but adds Java 5.0 to
your system. You'll then need to make sure that you're using the right
version of Java as you work with your assignments. This is tricky to
get right. Try this:
- Open up the Terminal.
Make sure that you are logged in as administrator by typing
sudo su root
and entering your password if prompted.
Change your directory by typing
cd /System/Library/Frameworks/JavaVM.framework/Versions
Type
rm CurrentJDK
to remove the shortcut to the old version of Java.
Type
ln -s 1.5.0 CurrentJDK
to make a shortcut to the new version of Java.
- Close your terminal window.
Open up a terminal and type
java -version
to confirm your version. You should see a version number like
1.5.0_xx (where xx is the latest release number).
To compile and run programs, open a Terminal 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.
Finally, once you have completed your work you will want to
transfer it to your department account so that you can test it there
before submitting. To do so, use the scp command:
scp [filename] [username]@prism.mathcs.carleton.edu:~
... and enter your Carleton password.
This connects to prism, which is one of our department
computers, and copies your file to your home directory.
If you actually want to connect to prism remotely to run
your code, do so by typing
ssh [username]@prism.mathcs.carleton.edu
... and enter your Carleton password. This will give you access as
if you were sitting in front of a terminal window here in the
department, but note that you will not have access to any kind of
graphics or images.
jEdit settings
We have made the following changes to the default settings for
jEdit. You may wish to do the same if you are using jEdit on your
computer.
- Utilities, Global Options, Editing: set tab width to 4, indent width
to 4, check soft (emulated with spaces) tabs
- Utilities, Global options, Text Area: uncheck end of line
markers