Using Java

You may use whatever implementation of Java you wish for 341, subject to the caveat that only Java 1.2-compliant implementations will run all the code in the textbook (though 1.1 compliant implementations will run 99%). Alan recommends the current Sun implementation (JDK 1.2). This is installed on the lab machines, and should be available on the machines in Sieg 232. You can also get this free for a personal machine -- go to the java.sun.com web page and look under "Products and APIs" to get the JDK 1.2, a.k.a. the "Java 2 Platform". The Java 2 Platform comes in several varieties; we recommend SDK Standard Edition version 1.2.2

Microsoft J++ is installed in the PC Lab in Sieg 232, and is the official lab-supported version. However, it may not be entirely compliant with the Java specification.

The Linux port of Sun's JDK 1.2 is available on the instructional linux machines (tahiti etc.).


Using Java on NT

Java's JDK 1.2 is available in some NT labs (such as Seig 232). The executables should be in C:\jdk1.2\bin. On most machines the paths are already set up. Put your java source code in some directory. Get an MSDOS prompt and connect to that directory.

A sample program is HelloWorld.java or type:

public class HelloWorld
{
   public static void main(java.lang.String[] args)
   {
      java.lang.System.out.println("Hello World");
   }
}
To compile this program:
javac HelloWorld.java 
This should create a HelloWorld.class file containing the compiled Java bytecodes. You can now run these through the bytecode interpreter:
java HelloWorld
Hello World

Setup Problems

First make sure Java JDK 1.2 is on your machine. Next check that C:\jdk1.2\bin is on your search path, and that the classpath environment variable is set to . (meaning current directory).

Adding C:\jdk1.2\bin to your PATH

To do this you should go to the Control Panel and then click on the System icon. Select Environment from the list at the top. Then you are given a window viewing your environment variables. The variable PATH (case not important) should be there. You can click on it and then add C:\jdk1.2\bin. Note that NT seperates seperate items in the path with the ; character not the : character. Now you should hit the Set button and then the Apply button. You might have to logout and log back in again for the path change to really happen.

If you have trouble getting this to work, you can go to a MSDOS prompt and type:

path C:\jdk1.2\bin;%path%

Using Java on the instructional Linux machines

To use Java on tahiti, ceylon, sumatra, etc, you should first make sure that /usr/local/bin is in your path. You need access to javac, the Java compiler, and java, the Java bytecode interpreter. To make sure you have access to these programs, try the following:
tahiti% which java
/usr/local/bin/java
tahiti% which javac
/usr/local/bin/javac
Then to compile HelloWorld:
tahiti% javac HelloWorld.java 
tahiti% ls
HelloWorld.class  HelloWorld.java
Note that this created the HelloWorld.class file. This file contains the compiled Java bytecodes. You can now run these through the bytecode interpreter:
tahiti% java HelloWorld
Hello World
You can follow this procedure to compile and run your own Java programs.