JDK 1.0.2 InnerClass Demonstration

Platforms Affected

InnerClasses were introducted with JDK 1.1. Does that mean you can't use them in JDK 1.0.2 browsers? No!

InnerClass source code needs to be compiled by a JDK 1.1 compiler, BUT the JDK 1.0.2 interpreter can still read the new class files behind the scenes.

Details On JDK 1.0.2 Inner Classes

Innerclasses are implemented behind the scenes by taking inner class source code and compiling separate class files out of them. JDK 1.0.2 interpreters happily resolve these Inner Class references as External Class references.

The applet below demonstrates this in action by using an interface which is implemented by two Event handler classes inside the main applet. This is a pseudo-controller Event mechanism. A more detail controller system can be found in Bruce Eckel's Thinking in Java book.

Basically, a button can be clicked to bring up a window with a selection list. When you click the selection list, it does a callback to a class that was passed to it.

Since we have two buttons though, we can't use the main class to implement the interface callback because of a naming conflict. But with inner classes, we can create two separate classes for handling each button's callback and pass an instance of those to the selection window.

Inner Class Warning

Older JDK 1.0.2 Browsers such as Netscape 3.x may have trouble reading some class files compiled with JDK 1.1 compilers.

Therefore, you use this technique at YOUR OWN RISK. Your mileage may vary. If you are having problems running your code on Netscape 3, you may need to drop back down to a JDK 1.0.2 compiler.

References

Bruce Eckel's Thinking In Java book gives an excellent introduction to Inner classes. There are other books that describe inner classes, but Bruce's explains where they are good to use.

Applet Demonstrating Inner Class Usage

View The Source To InnerClassTest.java
View The Source To ChoiceSelectorFrame.java
View The Source To ChoiceSelector.java

Gunther Birznieks <gunther@clark.net>