copyright

If your browser were Java-enabled, you would see the LissaDemo here.

THE LISSADEMO APPLET.
DRAWS RANDOM PATTERNS.

Java Review
LANGUAGE | TOOLS | SERVER | APPLICATION | FUTURE | RESOURCES



LANGUAGE


samples | introduction | timeline | standards | awt | beans | jfc

Last updated: October 1998

These pages constitute an overview of Java, summarizing the major developments and applications of the language to the current time. Some prior programming knowledge is assumed on the part of the reader. Use the navigation applet at the bottom of the page to reach the various sections of the review quickly. You can get a static version of the navigation control by clicking here.




samples

For reference here is a listing of the illustrative Java programs used in these pages. Most of them are applets because these can be run in a browser. If you have problems with any of them please complain to code@oranda.com, including information on your browser, browser version, and operating system. To ensure failsafe viewing of the applets you can download JavaSoft's Activator plug-in which works with both Netscape Navigator 3.0 and up and Internet Explorer 3.02 and up.

Name: OrandaNav
Author: James McCabe
Type: Applet
Compatibility: JDK 1.0
View this now in browser
Documentation
Name: TextScroll
Author: James McCabe
Type: Applet
Compatibility: JDK 1.1
View this now in browser
Documentation
Name: LissaDemo
Author: James McCabe
Type: Applet
Compatibility: JDK 1.0
View this now in browser
Documentation
Name: Lissa
Author: James McCabe
Type: Applet
Compatibility: JDK 1.0
View this now in browser
Documentation
Name: OrChatApp (including OrChatClient and OrChatServer)
Author: James McCabe
Type: Application
Compatibility: JDK 1.1
View this now in browser
Documentation
Name: SpeedSwitch
Author: James McCabe
Type: Applet
Compatibility: JDK 1.1
See beans section
Documentation




introduction to the language

Java is an object-oriented language derived from C++ with very strong support for networking and component-oriented development. Java source code is compiled to a form called bytecode which is platform-independent. The bytecode is stored in .class files which can be transferred across a network to machines of different types, and then converted by each machine to its native machine code, either by compiling with a JIT (just-in-time compiler) and running it method by method, or by interpreting it with a VM (Virtual Machine).

The key to Java's platform independence is simplicity. It achieves this by discarding some of C++ features and adding some of its own:

  • Java has no pointers.
  • Java has no multiple inheritance. The same effect is achieved by implementing interfaces.
  • Java has no preprocessor (hence no macros).
  • Java does not allow global variables.
  • Java has a singly-rooted hierarchy. (Everything is descended from Object).
  • There is strong support for exception handling — the compiler checks to make sure exceptions are properly caught using Exception classes.
  • There is also strong support for multithreading — the Thread class allows the programmer to quickly create and control lightweight processes.

As Java is simpler and stricter than C++ it makes some compromises:

  • Java is slower than C++. Interpreted code runs about twenty times slower. However code compiled with JIT compilers may approach C++ speeds.
  • Low-level tasks must be done by interfacing with other languages — native methods.
  • An application may be limited in what it can do over a network owing to Java's strong security model. In many ways this is a strength of course.



timeline

timeline

RESOURCES

An early Java Review from June 1996 including more historical information.




standards

The JDK (Java Development Kit) 1.0 established the first major public Java standard, with a C++-like syntax and a hierarchy of classes including support for the AWT (Abstract Windowing Toolkit), networking, streams, event handling, exception handling, and threads. Soon afterwards the JDBC (Java Database Connectivity) classes were introduced as a means of communicating with databases.

The JDK 1.1 was a major advance, including the following major improvements:

  • JavaBeans — the component-oriented model.
  • New event model for the AWT.
  • Remote Method Invocation — a means for objects in different Java environments to call each other's methods.
  • Serialization — the ability for objects to be written to and read from files.
  • JAR (Java Archive) file support.
  • Localization support.
  • New native method interface.
  • Nested classes allowed.
  • Miscellaneous performance improvements.
  • Initial support for GUI data transfer between Java applications — the Clipboard and Drag-and-Drop classes.
  • Various other AWT impovements including classes for printing, accessing the user's desktop color scheme, support for "lightweight" windows, a class to help scrolling (ScrollPane) and a class for pop-up menus.
Of these improvements probably the most significant are the introduction of JavaBeans, RMI, and the new event model. Regarding the last of these: in the JDK 1.1 events are generated by sources and objects can become listeners by registering with the sources. An object can delegate event handling to one of its components, e.g. a Panel delegating mouse event handling to a button. To listen to a source an object must implement the listener interface like this:

public class MyListener implements ActionListener {... }

This class must now provide the body of the method actionPerformed(ActionEvent e) specified in the ActionListener interface. (rather than the action method used in the JDK 1.0). There are different sets of listeners for different types of events: for instance the MouseListener interface can be used to respond to mouse-specific events like MouseEntered and MouseClicked. To save the developer the necessity of implementing all the methods of a given listener interface, the JDK 1.1 includes adapters for most listeners which give default empty bodies to each method — the developer can then simply extend the adapter and choose which methods he wishes to implement.

The JDK 1.2 has not been properly released yet but improvements include:

  • JFC (Java Foundation Classes) — the Swing GUI components, with associated functionality such as drag-and-drop.
  • The Servlet extension and an Extension Architecture.
  • enhancements to the JDK 1.1 features such as JavaBeans, RMI, Serialiation and the JNI (Java Naming Interface)
  • general performance improvements.
The JNI (Java Naming Interface) is used by Java to interact with libraries and applications written in other languages. A C program for instance could use the JNI to create the Java VM, start the Java application, attach to the VM, and inspect classes and methods in the Java application.

Where the JNI allows interaction with other languages, the JNDI (Java Naming and Directory Interface) is used to interact with standard directory services such as LDAP, NDS, DNS, and NIS. These plug in to the common JNDI interface much like the way databases plug in to the JDBC interface; the vendors of the services or databases have to provide implementations with support for the Java API. The JNDI is a standard extension implemented in the javax.naming.* package.

JavaSoft has been working hard to make Java graphics competitive, implementing its platform-independent Media APIs on top of platform-dependent graphics packages. The Java 2D API adds many graphical effects to the AWT: more colors and fonts; anti-aliased text; definition of objects independent of resolution using Bezier paths; transparency options; and many more additions. Furthermore there is a 3D API which can be a viewed as a competitor to VRML, although it is runtime in nature, rather than being based on static file-based representation of scenes -- however, as with VRML's scene graph it uses a hierachical system of organizing objects.

RESOURCES

The JDK 1.1 Event Model described by JavaSoft
JDK 1.1 features (from JavaWorld)
JDK 1.2 features (from JavaWorld)
Introduction to the JNI (from JavaWorld)
JNDI home page at JavaSoft




awt

The AWT is the basic Java GUI toolkit including classes for the essential controls used in a graphical application: frames, buttons, labels, select lists (Choice and List), text fields, text areas, scrollbars, menus, checkboxes etc.. The Canvas class allows general line drawing, but you have to get a Graphics object — fonts and colors are associated with the graphical context.

All the GUI elements are subclassed under the Component class. One of the subclasses of Component is Container class. Containers are graphical elements like panels or windows that hold other graphical elements. To place an element at a particular place in a container it is necessary to first specify a layout manager using setLayout and then use add. In other words elements are placed relative to each other rather than at specific coordinates. There are different layout managers provided: the most complex is GridBagLayout.

Lissajous Curves Example: Here is an example of code which uses the AWT classes to create a canvas, text fields, and a button. By changing the values in the text fields and clicking on the button, you can cause new patterns to be drawn on the canvas. I found the basic algorithm for these patterns in the book Computers and the Imagination by the graphical mathematician Pickover.




beans

The JavaBeans API was introduced with the JDK 1.1 and offers developers a standard way of creating re-usable components which can communicate with each other. The BDK (Bean Development Kit) is distributed separately and includes the beanbox program for linking beans and examining their details.

A Java bean is thought of in terms of three components: its properties, methods, and events. It is easy to turn nearly any simple Java program into a bean — just implement getter and setter methods for the data objects which can be used with other beans: for instance, if a class has a property color, it should have accessor methods getColor() and setColor(). In order to allow beans to be useful in the context of the beanbox or a more advanced GUI tool, it is necessary to implement the methods of a property change listener and also add lines of code such as the following:

private PropertyChangeSupport changes = new PropertyChangeSupport(this);

...and in the setter method...

changes.firePropertyChange("color", oldColor, newColor);

This notifies the beanbox that the property has been changed. The property color can be viewed in the Property Editor which support simple types of properties like int, string, etc.. It is also possible to define one's own property editor in code for more advanced types. Furthermore the states of beans can be saved between sessions because a key feature of beans is their ability to be written to and read from disk using the JDK 1.1 Serializable interface.

In order to package a class (e.g. an applet) as a bean it is necessary to archive it in a jar file, using a manifest.stub file to indicate which classes are beans. The jar can then be loaded within the beanbox or put into a jar folder which the beanbox uses at startup time. With this release it can be a bit tricky ensuring that everything is in the correct folders and archived correctly. In particular I discovered that if the bean wishes to load resources from relative URLs it cannot use getCodeBase() in the normal fashion.

Below is a example of a simple bean I created called SpeedSwitch. By clicking on the graphical space the user can move the switch to one of four states: off, slow, medium, and fast. The bean can be selected and dragged from the Toolbox (it is at the bottom) and the state is shown in the Property Editor along with other properties.

beans

Extra notes:

  • A recent development is the creation of an Enterprise JavaBean (EJB) framework for the use of developers creating business applications.



jfc

The JFC (Java Foundation Classes) are Sun's attempt to overcome the limitations of the AWT and enable developers to create professional-looking applications using a high-end GUI toolkit. JFC stands in direct competition to Microsoft's AFC/WFC (Application/Windows Foundation Classes) which are Windows-specific but allow programmers to use the wide array of controls available with the Win32 API. Another set of foundation classes, the IFC (Internet Foundation Classes), were provided by Netscape and were quite popular; these, however, are now integrated into the JFC.

The JFC is being released with JDK 1.2 (slated for November 1998; available in Beta). The four key sets of JFC classes are:

  • The Swing Set of GUI components (also available to developers separately).
  • A drag-and-drop API to interface with OS-specific system calls.
  • The Java 2D API to enhance graphical functions.
  • The Java Accessibility classes to help users with disabilities.

Other improvements include undo/redo support, clipboard (data transfer) support and much better printing functionality, Furthermore, all JFC components are JavaBeans - though their complexity has posed problems for developers.

Swing has been available independently for some time. Building applications with the primitive AWT toolkit had stretched developers' patience, but Swing includes all the main components that developers are used to working with — progress bars, tabbed panes, sliders, color choosers, etc. — in addition to extending the functionality of ordinary AWT components such as buttons and text boxes. It is also much more efficient, owing to the lightweight nature of all Swing components. This means that the drawing and events of each component is entirely controlled by Java; with the AWT's peer model it had been necessary to bind each component to its peer component on the native platorm. With Swing everything is drawn by Java and this has the added advantage that you can have an arbitrary look and feel on any platform, Swing has three different looks built in - Windows, Motif, and the default JLF (Java Look-and-Feel).

Swing uses the Model-View-Controller (MVC) paradigm well-known to Smalltalk programmers. Each component has a Model to represent internal state and a View-Controller (also called a delegate) for the graphical look. For instance there are ButtonModel and ButtonUI (delegate) interfaces for the JButton component. If you wanted a button to keep track of how many times it has been clicked you would implement the ButtonModel interface; if you wanted to create a new look-and-feel for the buttons in your application you would need to implement the UI interface. The programmer can change the default implementations of both the Model and the UI using the methods getUI(), setUI(), getModel(), and setModel().

Typically an application developer will want to create a main window which allows many sub-windows — a Multiple Document Interface (MDI). Swing introduces support for this — the JDesktopPane and JInternalFrame classes are particularly useful. For an example, here is an MDI application I am developing at the time of writing; it uses the default Java look-and-feel, showing one internal frame within a main JFrame. And this screenshot shows the components which might potentially go in such an application — taken from Sun's own demonstration program for Swing.