Java 1.2 Unleashed

Contents


- 1 -

What's New in JDK 1


The JDK 1.2 is a major upgrade of the Core and Standard Extension APIs of the Java Development Kit. It includes version 1.1 of the Java Foundations Classes (JFC), CORBA support, a more secure and flexible security model, improvements to the APIs of JDK 1.1, and performance enhancements. In this chapter you'll learn about the new capabilities added to JDK 1.2 and how these capabilities can be used to enhance your Java applets and applications. When you finish this chapter, you'll have a good understanding of what the JDK 1.2 provides and how to use this book to upgrade your Java programming skills to JDK 1.2.

The Java Foundations Classes

Probably the single most important new feature added to JDK 1.2 is version 1.1 of the Java Foundations Classes (JFC). JFC is a set of APIs for building the GUI-related components of Java applets and applications. JFC 1.1 was released separately from the JDK in February of 1998 so that they could be used with the then-current JDK 1.1. JDK 1.2 integrates JFC 1.1 as a Core API and adds the Java 2D and Drag and Drop APIs. The APIs included with JFC include the following:

These five APIs are introduced in the following subsections.

Abstract Windowing Toolkit (AWT)

If you've programmed in Java before, you know about the AWT. It provides the capability to create platform-independent, GUI-based programs and is a very important contributor to Java's popularity. Any programmer who has written programs using the arcane APIs of Microsoft Windows immediately appreciates the clarity, simplicity, and power of the AWT. Not only is the AWT a better API for developing Windows applications, it is a better API for programming window-based applications on platforms ranging from Motif to OS/2.

The AWT of JDK 1.2 has been augmented with many new classes and interfaces that add drawing, printing, and image-processing capabilities, and support the Accessibility, Drag and Drop, and Java 2D APIs. You'll learn to use the AWT in Chapter 6, "GUI Building," Chapter 7, "Working with the Canvas," and Chapter 9, "Creating Window Applications."

Swing

Of all the new capabilities provided by the JFC 1.1, one API, referred to as Swing, has far-reaching consequences for Java programmers. Swing is the code word used by the JavaSoft programming team for the next generation of the AWT. Swing extends AWT by supplying many more types of GUI components, providing 100% pure Java implementations of these components, and allowing the appearance and behavior of these components to be easily tailored.

The new components that are included with Swing include everything from tabbed panes and fancy borders to sliders and spinners. These new components, in and of themselves, make Swing an outstanding addition to the Java API. The Swing Component Gallery, located at http://java.sun.com/products/jfc/swingdoc-current/comp_gal.html, exhibits some of these new components. Swing also comes with a great demo program named SwingSet.

The Swing components are 100% pure Java. This means that they don't depend on the native windows implementation to support them. It also means that Swing components are available and consistent across all platforms. Although Swing components are implemented in terms of the underlying AWT, these components do not use AWT components. In fact, many of the traditional AWT components, such as buttons, lists, and dialog boxes, have been reimplemented as Swing components. Because of this, the AWT components behave more consistently across different platforms and are capable of providing additional features not supported by their native windowing platforms.

The most talked about feature of Swing is its support for pluggable look and feel (PL&F). If you like to customize your desktop, dabble in new color schemes, and do what it takes to make your windows fit your tastes and needs, PL&F is for you. The Swing PL&F architecture makes it easy to customize both the appearance and the behavior of any particular Swing control or any group of those controls. Swing also comes with several predefined L&Fs, including the default Metal L&F, the Motif L&F, and the Windows L&F. L&Fs for Macintosh and other platforms are also being developed.

You'll learn to program using Swing in Part IV, "Swing Programming."

Accessibility

The Accessibility API is a JFC API that has been added to JDK 1.2. It provides support for the use of assistive technologies with other JFC components. Assistive technologies, such as screen magnifiers and speech recognition systems, are intended for use by disabled users, but are also valuable tools for the average non-disabled user. These technologies provide non-standard ways of interacting with software applications. The Accessibility API of JDK 1.2 allows software developers to comply with the Federal Rehabilitation Act and Americans with Disabilities Act.

The Accessibility API consists of classes and interfaces for incorporating accessibility features into applets and applications. These classes and interfaces are provided in the java.awt.accessibility package. Chapter 9 covers the use of the Accessibility API.

Java 2D

If you develop any kind of graphics-related software, you'll appreciate the new Java 2D API. This API provides comprehensive support for two-dimensional drawing, image processing, graphics rendering, color management, and printing. It consists of an imaging model that supports line art, text, images, spatial and color transformations, and image compositing. The model is device-independent, allowing displayed and printed graphics to be rendered in a consistent manner. The Java 2D API is incorporated into the java.awt and java.awt.image packages. Chapter 20, "Working with 2D and 3D Graphics," covers the Java 2D API.

Drag and Drop

One of the nicer features of most windowing environments that has been conspicuously missing from Java is support for drag and drop. Drag and drop is typically used to organize desktops, manage files, open documents, and execute applications. The Drag and Drop API allows the JDK 1.2 to provide platform-independent support of drag and drop. It supports drag and drop within Java applications, between Java applications, and between Java and native platform applications. The Drag and Drop API is implemented in the java.awt.dnd package and is supported by classes and interfaces in other JFC packages. Chapter 16, "Working with Drag and Drop," shows how to use the Drag and Drop API.

Other New Capabilities

Besides integrating JFC 1.1 as a set of Core APIs, the JDK 1.2 provides a number of other new capabilities. These capabilities are covered in the following subsections.

Java IDL

The Common Object Request Broker Architecture (CORBA) is a standard approach to developing distributed objects for use in distributed object-oriented systems. CORBA was developed by the Object Management Group (OMG), a consortium of software companies and other organizations. The capability to use Java objects within CORBA is referred to as Java IDL and has been incorporated into JDK 1.2. Java IDL provides an API and a set of tools for interfacing Java objects with CORBA objects, and for developing CORBA objects in Java. Java IDL also includes a Java Object Request Broker (ORB) and an ORB name server. Chapter 41, "Java IDL and ORBs," shows how Java and CORBA can be used together.

The Collections API

The Collections API is a set of classes and interfaces that provide an implementation-independent framework for working with collections of objects. This API consists of eleven classes and eight interfaces that have been added to the java.util package. These classes and interfaces provide support for generic collections, sets, bags, maps, lists, and linked lists. These classes and interfaces can be easily extended to provide support for custom object collections. The Collections API is covered in Chapter 11, "Using the Utility and Math Packages."

The Java Extensions Framework

JDK 1.2 provides the capability to extend the Core API classes. Extensions are implemented as Java Archive (JAR) files that are installed in a particular directory or downloaded from a URL. Appendix E, "The Java Extensions Framework," shows how to work with both installed and downloaded extensions.

Reference Objects

Reference objects, introduced with JDK 1.2, store references to other objects. They are similar in function to C and C++ pointers, but do not provide access to specific memory addresses. The java.lang.ref package provides six classes that implement reference objects. These classes also provide the capability to notify a program when a referenced object is subject to garbage collection. This capability enables reference objects to be used to implement object-caching mechanisms. Chapter 10 introduces reference objects.

Package Version Identification

Package version identification is also a new capability that was introduced with JDK 1.2. It allows applets and applications to obtain version information about a particular Java package. This version information enables large complex applications to evolve over time, with some application packages being upgraded independently of others. The new Package class provides methods for obtaining package version information. This version information is stored in the manifest of .jar files. Chapter 10, "Writing Console Applications" covers the methods of the Package class.

Input Method API

The Input Method API is an addition to the JDK's internationalization support that enables text-editing components to receive foreign language text input through input methods. It is designed to support large character sets, such as Chinese, Japanese, and Korean. An input method lets users enter thousands of different characters using keyboards with far fewer keys. Typically, a sequence of several characters is typed and then converted to create one or more characters. The input method framework is covered in Chapter 19, "Internationalization."

Enhancements

In addition to the new capabilities identified in previous sections, the JDK 1.2 provides significant enhancements to APIs, tools, and language features that were introduced in JDK 1.1 and 1.0. These enhancements are covered in the following subsections.

Security

The security model enforced by the JDK has evolved from JDK 1.0 through JDK 1.1 to JDK 1.2. The model enforced by JDK 1.2 is both more secure and more flexible than that of preceding JDK releases. It eliminates security flaws found in previous JDK versions. Its flexibility has been enhanced because it provides users with the capability to specify security policies simply by editing the security permissions contained in their policy text files. In addition to policy improvements, the JDK 1.2 provides enhanced support and tools for working with digital certificates. Chapter 3, "The Extended Java Security Model," and Chapter 8, "Applet Security," cover the security enhancements of JDK 1.2.

JavaBeans

The JavaBeans support provided with JDK 1.2 includes the Glasgow JavaBeans release. The Glasgow release adds the runtime containment and services protocol, support for drag and drop, and the JavaBeans activation framework. The runtime containment and services protocol provides beans with the capability to interoperate with other beans and to learn information about their execution environment. The new drag and drop support provides beans with a more complete graphical user interface capability. The JavaBeans activation framework allows beans to be selectively instantiated and used to support dynamic program requirements. Part VII, "Creating JavaBeans," covers JavaBeans programming. Chapter 29, "Glasgow Developments," covers the new features added with the Glasgow JavaBeans release.

Reflection

Reflection support was introduced in JDK 1.1. Reflection enables classes, interfaces, and objects to be examined and their public fields, constructors, and methods to be discovered and used at runtime. These capabilities are used by JavaBeans, object inspection tools, Java runtime tools such as the debugger, and other Java applications and applets. JDK 1.2 provides the capability to identify a field, method, or constructor as suppressing default Java language access controls. This permits reflection to be better used with the more flexible JDK 1.2 security model. Chapter 10 covers the use of reflection.

Audio

JDK 1.1 provided the capability for applets to play audio files that were in the Sun Audio (AU) format. JDK 1.2 provides a new sound engine that allows audio files to be played by both applets and applications. The sound engine also provides support for the Musical Instrument Digital Interface (MIDI), the Microsoft Windows audio file format (WAVE), the Rich Music Format (RMF), and the Audio Interchange File Format (AIFF). Chapter 21, "Using Audio and Video," covers these new audio capabilities.

JAR

Java Archive (JAR) files were introduced in JDK 1.1. These files provide the capability to store multiple files within a single archive file. JAR files help you organize applets, applications, beans, and class libraries and provide more efficient use of network resources. JDK 1.2 JAR enhancements include improved tools for working with JAR files and new classes for performing JAR file input and output. Chapter 8 covers the use of JAR files.

RMI and Serialization

The Remote Method Invocation (RMI) API was introduced in JDK 1.1. It provides the capability for Java objects executing on a local computer to invoke the methods of objects that execute on remote computers. Object serialization is used to pass objects as parameters and return values in the remote method invocations.

The RMI API has been significantly enhanced in JDK 1.2. The Remote Object Activation framework supports remotely activated objects and object references that persist across multiple object activations. Serialization improvements provide the capability for alternative objects to be written to and read from streams in support of serialization. RMI is covered in Part 9, "Developing Distributed Applications." Object serialization is covered in Chapter 40, "Using Object Serialization and JavaSpaces."

JDBC

JDBC provides the capability to access databases from Java. According to JavaSoft, JDBC doesn't stand for anything. However, it is sometimes associated with "Java database connectivity." JDBC was introduced in JDK 1.1. JDK 1.2 includes an improved version of the JDBC-ODBC bridge driver and support for JDBC 2.0. Part X, "Database Programming," covers all aspects of JDBC.

Native Interface

The Java Native Interface (JNI) provides the capability for Java objects to access methods written in languages other than Java. In JDK 1.2, the JNI includes new capabilities for controlling the manner in which native methods interact with the Java Virtual Machine. Chapter 53, "Native Methods," shows how to develop native methods using the Java Native Interface.

Performance

The overall performance of the JDK tools has been greatly improved. First and foremost is the inclusion of a just-in-time (JIT) compiler with the JDK. Other performance enhancements include the use of native libraries for some performance-critical Core API classes, improvements to multithreading performance, and reduction in memory usage for string constants.

Important Language Changes

In JDK 1.2, the stop(), suspend(), and resume() methods of the Thread class have been deprecated because of errors and inconsistencies that may occur as the result of their use. Instead of using the stop() method, it is recommended that threads monitor their execution and stop by returning from their run() method. A thread may determine that its execution should be stopped as the result of monitoring the state of a shared variable. In addition, it is recommended that threads suspend and resume their own execution as the result of monitoring interface events, such as the value of shared variables. The wait() and notify() methods of the Object class should be used to cause a thread to wait on changes to the value of a shared variable.


NOTE: In addition to changes to the Thread class, other classes, interfaces, and methods have been deprecated in JDK 1.2. A complete description of these changes is included with the JDK 1.2 documentation. A deprecated API element is one that is still supported for backward-compatibility but is being phased out of future JDK versions.

Tools Changes

The tools provided with JDK 1.1 have been improved in JDK 1.2, and new tools have been added. The new keytool and javasigner tools replace the javakey tool of JDK 1.1. New tools included with JDK 1.2 include the following:

Appendix C, "The JDK 1.2 Toolset," summarizes the use of the tools provided with JDK 1.2.

Summary

In this chapter you learned about the new capabilities added to JDK 1.2. You learned about the JFC 1.1, the other new Core APIs added to JDK 1.2, the Servlets Standard Extension API, and improvements to the APIs of JDK 1.1. The next chapter, "The JDK 1.2 API," provides an overview of the packages that are contained in the Core and Standard Extension APIs of JDK 1.2.


Contents

© Copyright 1998, Macmillan Computer Publishing. All rights reserved.