Which Java can you run?

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);
 
   }
}

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. If your browser can't handle Java 1.1, you should find a browser that can, or find a suitable applet viewer.

Internet Explorer 4.0 seems to be able to run Java 1.1 applets.

Netscape Navigator/Communicator 4.0.3 claims to handle Java 1.1, but there are big holes in the implementation, particularly in the AWT.

Sun's appletviewer works fine; here are the UNIX commands for running one of the above applets.

    % javac Squares02.java
    % appletviewer Squares02.html
 

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.