|
THE LISSADEMO APPLET. DRAWS RANDOM PATTERNS. |
|
|
|
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.
|
||||||
|
|
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:
As Java is simpler and stricter than C++ it makes some compromises:
|
||||||
|
|
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:
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:
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
|
||||||
|
|
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.
Extra notes:
|
||||||
|
|
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:
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.
|