Which Java can you run?

I have been trying to run Java on a UNIX system under Netscape Communicator 4.0.3. Java 1.0 applets work fine, but Java 1.1 applets do not. Here are two copies of the same applet, with one minor change from Java 1.0 to Java 1.1. If you see four brightly colored squares, the applet works; if you see a single gray square, your browser could not execute the applet.

Java 1.0 Java 1.1
import java.awt.*;
import java.applet.*;

public class Squares01 extends Applet {

  public void paint (Graphics g) {

    Dimension d = size();     // Java 1.0 method
    int width  = d.width;
    int height = d.height;

    g.setColor (Color.red);
    g.fillRect (0, 0, width/2, height/2);
    
    g.setColor (Color.yellow);
    g.fillRect (width/2, 0, width/2, height/2);
    
    g.setColor (Color.green);
    g.fillRect (0, height/2, width/2, height/2);
    
    g.setColor (Color.blue);
    g.fillRect (width/2, height/2, width/2, height/2);

   }
}
import java.awt.*;
import java.applet.*;

public class Squares02 extends Applet {

  public void paint (Graphics g) {

    Dimension d = getSize();  // Java 1.1 method
    int width  = d.width;
    int height = d.height;

    g.setColor (Color.red);
    g.fillRect (0, 0, width/2, height/2);
    
    g.setColor (Color.yellow);
    g.fillRect (width/2, 0, width/2, height/2);
    
    g.setColor (Color.green);
    g.fillRect (0, height/2, width/2, height/2);
    
    g.setColor (Color.blue);
    g.fillRect (width/2, height/2, width/2, height/2);

   }
}

I can run Java 1.1 applets on my UNIX system using the appletviewer application, even though my browser can't handle them. On UNIX, the commands run something like this:

    % javac Squares.java
    % appletviewer Squares.html
Java is a moving target; the language definition has changed greatly in a short period of time. It is a good idea to work with the latest version that you reasonably can. Most browsers can handle Java 1.1 applets; if yours can't, you should upgrade to a version that can, or find a suitable applet viewer.

Note: If you use an appletviewer to view this page, it will ignore the HTML code and bring up two windows, one for each of the two applets on this page. You can look at the window titles to see which applet is which.

Back to class web page.