David Neto's page about using Java on CS Lab machines

Created July 24, 1997

This page describes how to use Java on the CS Lab Sun machines. You probably got here from my main Java page.

The Java Development Kit, version 1.1.3 is installed on the CS Lab Sun machines in /local/lib/jdk. Documentation is available from my page for Java oldies.

To use the JDK, put /local/lib/jdk/bin on your path. You may also need to add ``.'' (or wherever you put your compiled .class files) onto your CLASSPATH environment variable. See /local/lib/jdk/README for more details.

Here's a sample session showing a simple Java program being compiled and run. It's an application, run from the command line; applets (for embedding into web pages) are more involved.

Foo.java is a complete Java ``Hello world'' program.

bash$ cat Foo.java
public class Foo {
	public static void main(String[] args) {
		System.out.println("Hello world!");
Environment variable CLASSPATH tells the Java runtime environment where to find compiled classes. We put the current directory ``.'' on the path. The JDK can find its own classes automatically.
You will likely have other things on your PATH. Let's make sure we are using the installed JDK.
bash$ PATH=/local/lib/jdk/bin:/usr/bin:/bin
bash$ which javac
Compile class Foo in file Foo.java with the JDK compiler javac to produce Foo.class.
bash$ javac Foo.java
bash$ ls Foo*
Foo.class  Foo.java
Command java is the Java virtual machine. It is used to execute programs, i.e. a class that has a public static void main(String []) member. The suffix .class is automatically supplied: do not add it yourself.
bash$ java Foo
Hello world!
That's all! For regular use, you'll want to set environment variables CLASSPATH and PATH in your startup files (~/.cshrc, ~/.profile, or ~/.bashrc).
Back to David Neto's Java newbie page
Back to David Neto's Java oldie page
Back to David Neto's main Java page
Back to David Neto's programming page
Back to David Neto's home page