internet.com

Library

State of the Java SDK

by Don Larson

Sun's JDK 1.1 blends improved performance with new features and the bonus of Beans

Since its initial release in January of '96, Java has been heralded, hyperbolized and even harangued as the technology that would forever change the face of computing--and, according to some sources, perhaps the world--as we know it. A year-and-a-half later, it's still a bit premature to credit many global changes to the upstart language. But one thing's for certain: the world--or at least the pressures of a fast-paced market and the demands of hungry developers--has certainly changed Java.

In an effort to stabilize the growing number of Java adaptations, Sun's JavaSoft development unit has quickly and quietly picked up the pace of its revisions to the Java Development Kit, or JDK. The first beta of the much anticipated 1.1 release, unveiled last December, took nearly a year to make its public debut. From that time, less than ten weeks separated two additional betas and the FCS (Sun-speak for "First Customer Ship") of the finalized JDK 1.1 on February 18th. To help you keep pace with the changing face of Java, Web Developer® breaks down the many added and enhanced features offered in the latest JDK release and details how these improvements promise to put better functionality, productivity and performance in your Java development.

New and Improved

JavaSoft's latest effort is bigger and better in a number of important ways. Reading like the top five on every Java developer customer's wish list, the most substantial additions include a completely re-written and enhanced Abstract Window Toolkit (AWT); full specification of the JavaBeans component model; new security enhancements and signed applets; a new Java Archive (JAR) file format; and Remote Method Invocation (RMI) functionality. But the most requested feature by far was faster, faster, faster. And JDK 1.1 (at least by initial indications) delivers, with improved performance of the Java Virtual Machine (VM) on all platforms. Here's the specifics on these features and more:

Performance Enhancements

By re-writing the Interpreter loop of the Java VM in assembly language, 1.1 now sports a VM that runs up to five times faster on certain operations, according to JavaSoft reports. Overall speed of the VM has also increased: up to two times the speed of the 1.0.2 VM on Solaris, and a little over 1.5 times as fast on Windows 95 and NT. Better performance, along with enhanced memory management, are the most important improvements in the 1.1 release, says Arthur van Hoff, former Senior Staff Engineer at JavaSoft, author of the original Java compiler and HotJava browser, now CTO for Marimba, Inc. "It is essential for our products that the VM is fast and does not grow indefinitely. The 1.1 release is significantly faster and implements a much better garbage collector, which even cleans up classes that are no longer referenced." With Sun's acquisition of LongView Technologies in February, the bionics may just be beginning for the Java VM. See the concluding section, "Planning for the Future," for more details.

Abstract Window Toolkit

One of the most widely criticized areas of the 1.0 Java release, the AWT is significantly improved and the Windows (Win32) version completely re-written in 1.1, with an emphasis on better speed and consistency across platforms. The new Windows AWT, often buggy and slow in previous versions, is a complete Peer rewrite, which means 32-bit users get a totally redesigned Java interface to the native graphical environment. General enhancements to the AWT include clipboard functionality between Java and native applications, new APIs for printing, imaging and graphics enhancements and more flexible font support for internationalization. JavaSoft also added a new Delegation Event Model, in which events are represented by a more complex hierarchy of classes rather than an individual event class. This will enable interface components to register to receive user input rather than simply inherit sensitivity to it, allowing for better scalability in larger Java applications. The new JDK also ships with a simple AWT 1.1 Conversion Tool for converting 1.0.x method names to 1.1.

Perhaps one of the most significant AWT augmentations, however, is the Lightweight User Interface Framework. This feature allows you to directly extend the java.awt.Component and java.awt.Container classes to create lightweight, partially transparent components. In prior releases, the only way to create a new AWT component was to extend a Canvas or Panel class or subclass. Where these "heavyweight" components automatically inherited an opaque native window, lightweight components do not. Therefore, the Lightweight UI reduces the number of heavyweight classes, which means less resource consumption and greater flexibility. And since lightweight components utilize no native code for processing, their handling is 100% implemented in Java code, for a completely consistent look-and-feel across platforms.

All these enhancements add up to a new AWT that "is much faster, richer and more robust" than its predecessors, proclaims Miko Matsumura, Java Evangelist for JavaSoft, who listed it tops among the improvements he is most excited about. According to JavaSoft, the enhancements represent the "beginnings" of a richer infrastructure for larger-scale GUI development, indicating that even more AWT improvements will be part of Java's future directions, highlighted later in this article.

Java Beans

JavaBeans, Java's component model, was not scheduled to ship as part of the 1.1 release. To the surprise and delight of many, however, development of the Beans API finished ahead of schedule, allowing the full specification to be included among 1.1's new features. JavaBeans enables developers and third-party ISVs alike to create reusable components which can be integrated into Java applications. Because they interoperate with proprietary platforms like LiveConnect, ActiveX and OpenDoc, Beans provide a critical link in the "write once, run anywhere" potential of the language by insuring that Java code runs on every operating system and within any application environment.

The model is one of the most promising new features of the latest JDK release, states Bill Clarke, Chief Technologist for @Work Technologies, a Java and ActiveX development shop located in Silicon Alley. "JavaBeans enables developers a great deal of flexibility in developing component-based systems that can be fully integrated with existing architectures [such as] CORBA and ActiveX." Perhaps even more important where developers are concerned, Beans have the potential to greatly improve productivity and cut down on wasted code by reducing the drudgery of continually re-writing their code (or someone else's) for different platforms.

Security Enhancements and Signed Applets

The new security layer in JDK 1.1 contains some of the functionality of the full Java Security API, including digital signatures, message digests, key management and access control lists. These measures will enable Java developers to digitally sign their code and even sign entire JAR files, thereby providing, at least in theory, some proof of their origin. Useful for creating "digital fingerprints" of data, message digests give applications a method of unique, unforgeable data identification. The key management and access control features allow applications to manage permissions and keys for individual or group users, as well as interoperate with other systems at a high level.

Encryption is an important addition for legal and commercial applications, according to Javasoft's Matsumura. "The security features in 1.1 leverage the powerful security that is enabled by a 'safe' language like Java. Sandboxing can be made dependent on 'trusted' applets. This allows for signed code and much more sophisticated applications." As an added extra, all of the security APIs were written completely in Java, making the layer easily extensible so that new security techniques can be seamlessly integrated.

Java Archive Format

JAR files tackle one of the most fundamental problems with Java applets on the Web: loading speed. Browsers like Netscape's Navigator load individual class, image and sound files one-by-one, making a separate connection to the server each time. Based on the well- known ZIP technology, the JAR file format bundles and compresses multiple applets-- along with their class file, image and audio components--into a single file. Enabling even complex applets to be delivered in a single HTTP transaction, the JAR format greatly improves the download speed of applets delivered over the Net.

The JDK's new security features also allow applet authors to digitally sign individual components in a JAR file to authenticate their origin. "JAR files and digital signatures make it possible to distribute trusted (i.e., secure) Java applets that can run outside of the Java sandbox," adds @Work's Clarke. "These applets can now be much more robust."

Remote Method Invocation

As its name implies, RMI allows Java objects running on one virtual machine to invoke methods on remote objects as if they were available locally. This applies to objects under the jurisdiction of another VM--even on another host or across a network. In prior releases, method calls were restricted to objects under the scope of the host VM. With RMI, however, programmers can create distributed, Java-to-Java, network-based applications, a fact particularly pleasing to enterprise developers, who need to access objects on distributed databases over corporate networks.

But Wait, There's More!

While the features noted above provide the most prominent grounds for celebration in the continuing Javafest, a number of lower-profile enhancements also contribute significantly to the new JDK. New internationalization features, for instance, make possible the development of localizable applets that display Unicode 2.0 characters and adapt text and numbers to any country's conventions. Similar extensions to the Input/Output (I/O) package enable it to handle character streams composed of 16-bit Unicode characters, rather than the usual eight-bit bytecode. Because character streams are not dependent on a specific character encoding, developers can write programs that are easy to internationalize.

First released in February of '96, Java's database interface, JDBC (a designation everyone except Sun recognizes as an acronym for Java DataBase Connectivity) is not new in the strictest sense, but it is new as part of the core API in JDK 1.1. Instead of requiring multiple programs to connect to different databases, JDBC enables Java developers to write a single program capable of sending SQL statements to almost any flavor of relational database, whether Oracle, Sybase, Informix or another brand. JDBC extends Java's platform independence to the next level, so that even databases can interoperate regardless of platform.

The JDBC API also includes an ODBC (Microsoft's Open DataBase Connectivity) Bridge, which basically lets JDBC use part of ODBC's functionality to do things like access a specific database's drivers. Along with a lower learning curve, JavaSoft also claims that JDBC is more secure than ODBC, due to the fact that Microsoft's interface makes calls to native C code.

Another enhancement in 1.1 is a new native method programming interface known as the Java Native Interface, or JNI. JNI insures the interoperability of Java native methods with applications and libraries written in other programming languages, such as C++ and assembly. JavaSoft's goal for the JNI is full compatibility of native method libraries across all implementations of the VM on a given platform. Especially beneficial in applications that can't be written entirely in Java, the JNI allows programmers to write a single version of a native application or library and expect it to work with all virtual machines supporting the JNI.

Yet another new, if somewhat more complicated feature of the JDK, is Reflection. Generally speaking, the idea behind reflection is that Java programs should be more self- aware, so that they actually play a role in programming themselves. Reflection provides objects and classes that can be used to represent the objects and classes in a Java application, basically allowing a program to describe itself--to itself--as it runs. To give a more concrete example, instead of having to code all the methods and classes you want to use into a program in advance, reflection lets you treat the methods and classes themselves like variables. The program is then able to decide the appropriate methods and classes to plug in as it runs.

Finally, Object Serialization is a new feature that adds support for objects to the core Input/Output classes of Java. The most basic benefit of serialization is that it allows for the persistence of objects after a program stops running. In Java applications built on previous JDK releases, a program had to create objects anew every time it started. For large applications or programs that are frequently stopped and restarted, this process of re- instantiating and setting up objects can be quite burdensome. Object serialization simply records the state of an object at the time a program stops and reloads it in that state when the program is restarted. Serialization converts objects into a single-file data stream, so it is also useful for transmitting objects between Java programs, even over a network.

A few miscellaneous enhancements are worth mentioning before moving on. First, Java's networking classes are now extendible. This allows extended sockets to be used wherever a base Socket class is used without rewriting application code. It is now possible, therefore, to create Socket subclasses that transparently use compression, for example, or even mirror traffic to multiple servers. To provide a simpler syntax for creating adapter classes, 1.1 also adds Inner classes, thereby giving Java the concepts of lexical scoping and block structure found in many other programming languages.

Last but not least, the latest JDK adds two new classes, BigInteger and BigDecimal, to its math package. Among its other contributions, the BigInteger class provides operations for modular arithmetic and single-bit manipulation. Meanwhile, BigDecimal allows a user to specify an explicit rounding behavior for operations capable of discarding precision, in addition to adding operations such as scale manipulation and hashing.

The Fine Print

Of course, there is one caveat to consider where all of Java's new functionality is concerned: applets compiled with 1.1 will not run on browsers (or other runtime systems) that support prior JDK releases. And even though licensees like Netscape and Microsoft are required by Sun to implement the 1.1 API within a "reasonable time" of first customer ship (six months is considered the guideline), it will be some time before these new browsers comprise a broad base of users on the Web.

For those who wish to begin delivering 1.1-based applets over the Web while still insuring backward compatibility, JavaSoft offers these still-experimental-at-press-time options (see the URL under "Providing Both 1.1 and 1.0.2 Applets" in our Resources sidebar for more info and source code):

  • Two applets, one HTML page. This method is a hack which relies upon the fact that only browsers supporting 1.1 will understand the new ARCHIVE attribute of the <APPLET> tag. It involves storing the 1.1 version of the applet as a JAR file in one directory and storing the 1.0.2 version in a separate directory. Browsers that understand the ARCHIVE attribute will retrieve the 1.1 applet, while older browsers will ignore the attribute and run the 1.0.2 applet.
  • One applet with mixed code, one HTML page. This approach places calls to 1.1 methods inside try statements and 1.0.2 code inside catch statements. Applets in 1.0.2 browsers will get an exception when they run the 1.1 code and will begin executing the 1.0.2 code within the catch statements instead.
  • Two applets, two HTML pages. Let the end users decide for themselves which version is right.

Planning for the Future

What new features will be added to future faces of Java? Well, at the rate JavaSoft is moving these days, you may already know by the time this issue hits the stands. Fearing that loose lips steal sips (or perhaps dreading even more really bad coffee puns), JavaSoft and Sun remain rather tight-lipped about their plans for the language in the near future.

By best guesstimates, however, more about the technology that the acquisition of LongView Technologies brought to Sun was probably the big news at JavaOne in early April. Word on the street at press time is that it is not just another just-in-time compiler, but an optimizer for the VM that also brings with it even better garbage collection. If true, the current speed record held by Microsoft's JIT could be in jeopardy.

What JavaSoft is saying with some assurance is that upcoming releases will continue to focus on some of the same areas that 1.1 addresses. According to Eric Chu, JDK Product Manager, the JavaSoft team is still targeting performance, improvements to the AWT and security as it eyes the future. Of these, they are most vocal about the continuing evolution of the window toolkit, with plans to add features including peerless and more sophisticated components (e.g., TreeView, Table and Styled-text), a "pluggable" look-and-feel model, drag-and-drop functionality and Java 2D. For more details, visit the URL of "AWT: The Next Generation" included in the Resources sidebar.

Finally, although new features like RMI and Object Serialization make distributed systems possible, they do not make such systems easy to design. JavaSpaces, an advanced research topic under the direction of JavaSoft's Java Systems East unit, is the specification that will deliver the tools and technology needed to make distributed systems easier to implement. Still in alpha as this issue went to press, the JavaSpaces spec is currently focusing on mechanisms to provide distributed persistence and data exchange to Java. These features will allow developers to write systems to store state and use a "flow-of-data" approach to implement distributed algorithms.

In contrast to the traditional approaches of distributed computing, which would require programmers to create particular remote interfaces for each client, the flow-of-data approach uses a single, uniform interface as defined in the JavaSpace spec. JavaSpaces works by allowing clients to write data, or "entries," into a particular public JavaSpace. An entry is a typed group of objects expressed in a Java class. JavaSpaces provides a mechanism for storing entries as related objects and then retrieving them based on a value- matching lookup for specified fields, making it possible to store and retrieve data on a remote system. For more details, visit the "JavaSpaces" URL listed in the Resources sidebar.

In the end, a robust new JDK and an ever-accelerating revision cycle both point to one thing: Sun and JavaSoft are no longer standing still, and they will not be content to sit back and let other vendors in the Java market decide the future direction of the burgeoning language. The battle is on, and the first to bring to market the gold version of Java that will set the reference standard wins. Meanwhile, the development community can only hope that that which makes Java stronger, doesn't kill it in the process.


Don Larson is Associate Editor of Web Developer®.

Reprinted from Web Developer® magazine, Vol. 3 No.2 Mar/Apr 1997 (c) 1997 internet.com Corporation. All rights reserved.


Web Developer® Site Feedback
Web Developer®
Copyright © 2000 internet.com Corporation. All rights reserved.

http://www.internet.com/