Java 1.2 Unleashed

Contents


- 2 -

The JDK 1.2 API


Chapter 1, "What's New in JDK 1.2," provided an overview of the new features incorporated into JDK 1.2. This chapter examines the JDK 1.2 API in closer detail. It provides an overview of the API packages and identifies the packages that have been added since JDK 1.1. It then describes all of the packages of JDK 1.2, highlighting important classes and interfaces. When you finish this chapter, you'll know your way around the packages of JDK 1.2 and know what packages to use for different programming needs.

API Overview

The JDK 1.2 API consists of 57 packages, all of which are in the Core API. Of the 53 Core API packages, 22 are part of the Java Foundations Classes (JFC). Figure 2.1 provides an overview of the JDK 1.2 packages.

The Core API is the minimum subset of the Java API that must be supported by the Java Platform. All classes and interfaces that are part of the JDK but are not in the Core API are in the Standard Extension API. The JFC are Core API classes and interfaces that support GUI development for applets and applications.

Figure 2.2 identifies the packages provided with JDK 1.1. By comparing Figure 2.1 with Figure 2.2, you can see that JDK 1.2 added 35 packages to the 22 packages provided with JDK 1.1. This is a substantial addition. The new JDK 1.2 packages are represented in boldface in Figure 2.1.

Core API

The Core API grew significantly from JDK 1.1 to 1.2. Of the 35 Core API packages that were added in JDK 1.2, 19 are in the JFC (10 Swing and 9 non-Swing), 9 are Java IDL (CORBA and CosNaming), 2 are security, 2 are utility packages (JAR and MIME support), 1 is JavaBeans, 1 is RMI, and 1 is object references (java.lang.ref). The bulk of the new JDK 1.2 packages are JFC and CORBA.

The following subsections summarize the JDK 1.2 Core API packages and identify what's new and what has been updated.

The java.applet Package

The java.applet package is one of the smallest packages in the Core API. It consists of one class and three interfaces that provide the basic functionality needed to implement applets. The Applet class provides methods to display images, play audio files, respond to events, and obtain information about an applet's execution environment. The AppletContext interface defines methods that allow an applet to access the context in which it is being run. The AppletStub interface supports communication between an applet and its browser environment, and is used to develop custom applet viewers. The AudioClip interface provides methods that support the playing of audio clips. The java.applet package is covered in detail in Part II, "Applet Programming."

FIGURE 2.1. The packages of JDK 1.2.


FIGURE 2.2. The packages of JDK 1.1.

The JFC Packages

The JFC packages provide the capability to create graphical user interfaces for applets and applications. The JFC packages subsume and extend the AWT of JDK 1.1. The number of JFC/AWT packages grew from 4 in JDK 1.1 to 23 in JDK 1.2. The 19 new packages include 10 Swing packages, written entirely in Java, that provide a pluggable look and feel for GUI controls. Other new packages support accessibility, drag and drop, 2D graphics, and imaging.

The java.awt Package

The java.awt package implements the core classes and interfaces of the Abstract Windowing Toolkit (AWT). It is a large package, containing 63 classes and 14 interfaces. These classes and interfaces provide the standard AWT GUI controls, as well as drawing, printing, and other capabilities. The java.awt package is covered in Chapter 6, "GUI Building," Chapter 7, "Working with the Canvas," Chapter 9, "Creating Window Applications," Part V, "Enhancing Your Applets and Applications," and Part VI, "Multimedia Programming."

The com.sun.java.accessibility Package

The com.sun.java.accessibility package provides seven classes and seven interfaces that support the use of assistive technologies for disabled users. It is covered in Chapter 9.

The java.awt.color Package

The java.awt.color package is part of the Java 2D API. It provides five classes that support the capability to work with different color models. The java.awt.color package is covered in Chapter 20, "Working with 2D and 3D Graphics."

The java.awt.datatransfer Package

The java.awt.datatransfer package provides four classes and three interfaces that support clipboard operations. It is covered in Chapter 15, "Using the Clipboard."

The java.awt.dnd Package

The java.awt.dnd package supports the new JDK 1.2 drag-and-drop capability. It contains 15 classes and four interfaces and is covered in Chapter 16, "Working with Drag and Drop."

The java.awt.event Package

The java.awt.event package provides the foundation for JDK 1.1-style event processing. It contains 21 classes and 13 interfaces, and is covered in Chapter 6.

The java.awt.font Package

The java.awt.font package is new to JDK 1.2. It provides 15 classes and two interfaces that support advanced font capabilities. The java.awt.font package is covered in Chapter 20.

The java.awt.geom Package

The java.awt.geom package is another new JDK 1.2 package that is part of the Java 2D API. It provides 30 classes and one interface that support standard geometrical objects and transformations. The java.awt.geom package is covered in Chapter 20.

The java.awt.im Package

The java.awt.im package is a new package that supports the Input Method API. It contains two classes and one interface. The Input Method API is covered in Chapter 19, "Internationalization."

The java.awt.image Package

The java.awt.image package is a Java 2D API package that supports image processing. It provides 38 classes and 8 interfaces that support common image filters. The java.awt.image package is covered in Chapter 20.

The com.sun.image.codec.jpeg Package

The com.sun.image.codec.jpeg package provides three classes and four interfaces that support JPEG image compression. It is covered in Chapter 20.

The java.awt.image.renderable Package

The java.awt.image.renderable package provides four classes and three interfaces that support image rendering. It is covered in Chapter 20.

The java.awt.print Package

The java.awt.print package is a Java 2D API package that supports the printing of text and graphics. It contains four classes and three interfaces. This package is covered in Chapter 18, "Printing."

The Swing Packages

The Swing packages are an important addition to the JDK 1.2. Swing is a 100 percent Java extension to the AWT that provides many new GUI components, improvements to existing components, and the capability to select from a variety of GUI look-and-feels, such as Metal, Windows, Motif, and Macintosh. Swing consists of 10 packages that are summarized in the following subsections and covered in detail in Part IV, "Swing Programming."

The com.sun.java.swing Package

The com.sun.java.swing package is the core Swing package. It contains 90 classes and 23 interfaces that provide the foundation for the Swing API. This package is introduced in Chapter 12, "Introducing Swing."

The com.sun.java.swing.border Package

The com.sun.java.swing.border package provides nine classes and one interface that implement borders and border styles. It is covered in Chapter 13, "Working with Swing Components."

The com.sun.java.swing.event Package

The com.sun.java.swing.event package provides 23 classes and 23 interfaces that implement Swing events and event listeners. It is covered in Chapter 12 and Chapter 13.

The com.sun.java.swing.plaf Package

The com.sun.java.swing.plaf package provides 42 classes and one interface that support the use of the pluggable look and feel. It is covered in Chapter 14, "Changing the Look and Feel of Your Swing Components."

The com.sun.java.swing.table Package

The com.sun.java.swing.table package provides seven classes and four interfaces that implement the Swing table component. It is covered in Chapter 13.

The com.sun.java.swing.text Package

The com.sun.java.swing.text package provides 59 classes and 21 interfaces that implement text processing components. It is covered in Chapter 12.

The com.sun.java.swing.text.html Package

The com.sun.java.swing.text.html package consists of 22 classes that provide basic HTML editing capabilities. This package is covered in Chapter 12.

The com.sun.java.swing.text.rtf Package

The com.sun.java.swing.text.rtf package consists of a single class, RTFEditorKit, that provides the capability to edit Rich Text Format (RTF) documents. It is covered in Chapter 12.

The com.sun.java.swing.tree Package

The com.sun.java.swing.tree package provides four classes and seven interfaces that provide the capability to work with com.sun.java.swing.JTree components. The JTree component is a GUI component that displays a set of hierarchical data as an outline. The com.sun.java.swing.tree package is covered in Chapter 13.

The com.sun.java.swing.undo Package

The com.sun.java.swing.undo package provides five classes and two interfaces that support the implementation of undo and redo capabilities. It is covered in Chapter 13.

The JavaBeans Packages

Two JavaBeans packages are provided with JDK 1.2. The java.beans package was present in JDK 1.1. The java.beans.beancontext package has been added to support the implementation for a bean container that provides an execution context for beans during design and runtime execution.

The java.beans Package

The java.beans package contains 15 classes and eight interfaces that provide the basic JavaBeans functionality. The java.beans package is covered in Part VII, "Creating JavaBeans."

The java.beans.beancontext Package

The java.beans.beancontext package provides 11 classes and eight interfaces that implement an execution context for beans. The java.beans.beancontext package is covered in Chapter 29, "Glasgow Developments."

The java.io Package

The java.io package provides 50 classes and 10 interfaces that implement stream-based input and output. Chapter 17, "Input/Output Streams," shows how to use java.io to perform a wide variety of input and output.

The Language Packages

The three java.lang packages implement the core classes of the Java language and runtime environment. The java.lang.ref package is new to JDK 1.2. This package introduces reference objects, which are objects that are used to reference other objects.

The java.lang Package

The java.lang package provides 29 classes and three interfaces that implement fundamental Java objects. Because of its importance, the java.lang package is included with all Java platforms, ranging from EmbeddedJava to the full-blown JDK. The java.lang package is covered in Chapter 10, "Writing Console Applications."

The java.lang.ref Package

The java.lang.ref package provides five classes that implement the new JDK 1.2 reference object capability. Reference objects are objects that are used to refer to other objects. They are similar to C and C++ pointers. The java.lang.ref package is covered in Chapter 10.

The java.lang.reflect Package

The java.lang.reflect package contains seven classes and one interface that provide the capability to implement runtime discovery of information about an object's class. The AccessibleObject and ReflectPermission classes are new to JDK 1.2. The java.lang.reflect package is covered in Chapter 10.

The java.math Package

The java.math package provides two classes, BigDecimal and BigInteger, that provide the capability to perform arbitrary-precision arithmetic. This package is covered in Chapter 11, "Using the Utility and Math Packages."

The java.net Package

The java.net package provides 21 classes and five interfaces for TCP/IP network programming. The java.net package is covered in Part VIII, "Network Programming."

The RMI Packages

The five Remote Method Invocation (RMI) packages provide the capability to use distributed objects within Java. The java.rmi.activation package is new to JDK 1.2. It supports persistent remote object references and automatic object activation. Part IX, "Developing Distributed Applications," covers programming with the RMI packages.

The java.rmi Package

The java.rmi package provides three classes and one interface that support basic RMI capabilities. The MarshalledObject class is new to JDK 1.2. It supports object persistence for remote object activation. The Naming class provides static methods for accessing remote objects via RMI URLs. The RMISecurityManager class defines the default security policy used for remote object stubs. The Remote interface is used to identify an object as being remotely accessible. The java.rmi package is covered in Chapter 38, "Building Distributed Applications with the java.rmi Packages," and Chapter 39, "Remote Method Invocation."

The java.rmi.activation Package

The java.rmi.activation package supports persistent object references and remote object activation. It contains seven classes and four interfaces. Chapter 39 shows how to work with these classes and interfaces.

The java.rmi.dgc Package

The java.rmi.dgc package supports distributed garbage collection. It contains two classes and one interface. The Lease class creates objects that are used to keep track of object references. The VMID class implements an ID that uniquely identifies a Java virtual machine on a particular host. The DGC interface is implemented by the server side of the distributed garbage collector. The java.rmi.dgc package is covered in Chapter 38.

The java.rmi.registry Package

The java.rmi.registry package supports distributed registry operations. It contains one class and two interfaces. The LocateRegistry class provides methods for accessing the Registry on a particular host. The Registry interface provides methods for associating names with remotely accessible objects. The RegistryHandler interface provides methods for accessing a Registry implementation. These methods have been deprecated in JDK 1.2. The java.rmi.registry package is covered in Chapter 38.

The java.rmi.server Package

The java.rmi.server package provides the low-level classes and interfaces that implement RMI. It contains 11 classes and nine interfaces. The SocketType class is new to JDK 1.2. The java.rmi.registry package is covered in Chapter 38.

The Security Packages

The five java.security packages support the implementation of the JDK 1.2 configurable security policy and cryptographic security mechanisms. These packages are covered in Chapter 3, "The Extended Java Security Model," and Chapter 8, "Applet Security."

The java.security.cert and java.security.spec packages are introduced in JDK 1.2. The java.security.cert package supports digital certificates. The java. security.spec package provides specifications for the keys used in common cryptographic algorithms.

The java.security Package

The java.security package provides 37 classes and eight interfaces that form the foundation for the Security API. Refer to Chapter 3 and Chapter 8.

The java.security.acl Package

The java.security.acl package provides five interfaces that form the basic elements for implementing security access controls. This package is covered in Chapter 8.

The java.security.cert Package

The java.security.cert package provides seven classes and one interface that implement digital certificates. It is covered in Chapter 8.

The java.security.interfaces Package

The java.security.interfaces package provides eight interfaces that support implementation of the NIST digital signature algorithm. It is covered in Chapter 8.

The java.security.spec Package

The java.security.spec package provides nine classes and two interfaces that provide specifications for cryptographic keys. It is covered in Chapter 8.

The java.sql Package

The java.sql package provides six classes and 18 interfaces that provide Java database connectivity. This package is covered in Part X, "Database Programming."

The java.text Package

The java.text package provides 20 classes and two interfaces that support internationalization. The java.text package is covered in Chapter 19.

The Utility Packages

The four java.util packages provide a variety of useful classes and interfaces for both applets and applications. These packages are covered in Chapter 11.

The java.util.jar and java.util.mime packages are new to JDK 1.2. The java.util.jar package provides classes for working with Java Archive (JAR) files. The java.util.mime package provides classes for working with Multipurpose Internet Mail Extensions (MIME) types.

The java.util Package

The java.util package, like java.lang and java.io, is fundamental to any Java platform. It provides 34 classes and 13 interfaces that cover a wide variety of common programming needs. Most of the new classes and interfaces support the Collections API. The java.util package is covered in Chapter 11.

The java.util.jar Package

The java.util.jar package provides seven classes for working with JAR files. It is covered in Chapter 11. Chapter 8 shows how to use the jar tool to create JAR files.

The java.util.mime Package

The java.util.mime package provides two classes for working with MIME types. The MimeType class provides an object representation of a MIME type. The MimeTypeParameterList class provides the capability to work with a MIME type's parameters. The java.util.mime package is covered in Chapter 11.

The java.util.zip Package

The java.util.zip package provides 14 classes and one interface for working with compressed files. It is covered in Chapter 11.

The CORBA Packages

The six new CORBA packages represent a sizable addition to the Core API and a significant capability for the Java programmer. These packages allow Java objects to make remote method invocations of CORBA objects. They also allow Java objects to be accessed as CORBA objects. The following subsections summarize these packages. Chapter 41, "Java IDL and ORBs," shows how to use these packages to interface Java with CORBA.

The org.omg.CORBA Package

The org.omg.CORBA package consists of 57 classes and 42 interfaces that implement the foundation for supporting Java-CORBA integration.

The org.omg.CORBA.ContainedPackage Package

The org.omg.CORBA.ContainedPackage package contains a single class, Description, that describes the type and value of a contained object.

The org.omg.CORBA.ContainerPackage Package

The org.omg.CORBA.ContainerPackage package contains a single class, Description, that describes the type, value, and object of a contained in the container object.

The org.omg.CORBA.InterfaceDefPackage Package

The org.omg.CORBA.InterfaceDefPackage package contains a single class, FullInterfacedescription, that describes an interface definition.

The org.omg.CORBA.ORBPackage Package

The org.omg.CORBA.ORBPackage package defines the InvalidName exception, which is raised when an invalid name is passed to an object request broker.

The org.omg.CORBA.TypeCodePackage Package

The org.omg.CORBA.TypeCodePackage package defines the BadKind and Bounds exceptions, which are used to signal exceptions related to type usage and constraints.

The org.omg.CORBA.portable Package

The org.omg.CORBA.portable package consists of five classes and three interfaces that are used to support vendor-specific CORBA implementations.

The org.omg.CosNaming Package

The org.omg.CosNaming package consists of 20 classes and two interfaces that implement a tree-structured naming service.

The org.omg.CosNaming.NamingContextPackage Package

The org.omg.CosNaming.NamingContextPackage package consists of 13 classes that implement aspects of the naming service's name context. The name context implements nodes within the tree-structured naming scheme.

Standard Extensions

The Servlet API is a Standard Extension API, which provides the capability to perform server-side programming with Java. Java Servlets are used to replace Common Gateway Interface programs on Web servers. They can also be used to implement other, non-Web services. The Servlet API consists of the javax.servlet and javax.servlet.http packages. The javax.servlet package consists of three classes and six interfaces that allow Servlets to communicate with clients, process client requests, and send return responses to these requests. The javax.servlet.http package contains four classes and five interfaces that support the Hypertext Transfer Protocol (HTTP). Chapters 47, "Sun's Java Web Server," and Chapter 48, "Programming Other Servers," cover the Servlets API.

Other APIs

In addition to the Core and Standard Extension API packages covered in the previous sections, JavaSoft is currently developing other APIs that support other programming needs. Many of the APIs will become incorporated into future versions of the JDK as Core API or Standard Extension API packages. The new APIs covered in this book are described in the following subsections.

Java 3D

The Java 3D API provides the capability to create three-dimensional graphics applets and applications. It consists of classes and interfaces that support 3D objects and transformations. The Java 3D API is covered in Chapter 20.

The Java Media Framework

The Java Media Framework provides support for playing audio, video, and other multimedia within Java applets and applications. It supports a wide range of audio and video formats and provides animation capabilities. The Java Media Framework is covered in Chapter 21, "Using Audio and Video."

The Speech API

The Speech API adds speech recognition and synthesis capabilities to Java. The Speech API is covered in Chapter 23, "Integrating Speech and Telephony Capabilities."

The Telephony API

The Telephony API provides the capability to develop telephony applications, such as call center applications. The Telephony API is covered in Chapter 23.

JavaMail

JavaMail provides a set of classes and interfaces for developing client and server components of email systems. JavaMail is covered in Chapter 34, "Using JavaMail."

Java Naming and Directory Services

The Java Naming and Directory Interface (JNDI) allows Java applets and applications to access naming and directory services using protocols such as the Lightweight Directory Access Protocol (LDAP). The JNDI API is covered in Chapter 35, "Naming and Directory Services."

The Java Management API

The Java Management API provides a Java-based framework for managing enterprise networks and network resources. It is covered in Chapter 36, "Working with the Java Management API."

JavaSpaces

JavaSpaces supports the development of distributed applications by providing persistent distributed object capabilities. It is covered in Chapter 40, "Using Object Serialization and JavaSpaces."

JavaCommerce

The JavaCommerce API provides the capability to build electronic commerce applications in Java. It is covered in Chapter 50, "Java Commerce and JavaCard."

Summary

This chapter examined the JDK 1.2 API in close detail. It provided an overview of the API packages and identified the packages that have been added since JDK 1.1. It described all of the packages of JDK 1.2, highlighting important classes and interfaces. The next chapter will focus on Java security and the new extendible security model that is supported by JDK 1.2.


Contents

© Copyright 1998, Macmillan Publishing. All rights reserved.