Friday, October 08, 2004

Java 5 features

The new features in Java 5 can roughly be organized into four categories: enhanced language features, Virtual Machine upgrades, library updates, and desktop (UI) enhancements.

Language Features
There is a long list of language features that could be mentioned, but we will only take time to address some of the most significant developments.
Enumerated types – An enumerated type is a datatype containing a fixed set of constant values. As implemented in J2SE 5.0, enums are object-oriented (users can define methods and fields) and typesafe.

Formatted I/O – Console output has been enhanced by implementing printf-style formatters, enabling many legacy C applications to be ported without changing the expected output format. On the input side of the house, the Scanner API has been provided to offer developers a more robust mechanism for reading in data types rather than simply parsing strings from buffered System.in calls.

Generic types – Perhaps the most significant enhancements made to the Java language revolve around the introduction of generic types. Gone are the days when Java developers must toil and sweat to cast objects up and down the type hierarchy. With generic types, a collection’s type can be specified at compile time to permit compile type checks and ease development by providing implicit type casting. Additionally, primitive types are now able to automatically convert (autoboxing/unboxing) between the primitive type and its corresponding Object wrapper (int <----> Integer, boolean <----> Boolean, char <----> Char, etc.).

Metadata – J2SE 5.0 now supports the inclusion of metadata related to Java classes, interfaces, fields, and methods. Development tools are the intended consumers for this metadata to support the automated insertion of additional source code, debugging functionality, and creation/modification of external XML files or configuration files to support application runtime and deployment.

Varargs – With J2SE 5.0, support for passing a variable number of arguments into a method has been added. By using a special notation (…) in the method signature’s parameter list, an ad hoc Object array can be created.

Java Library

There are two new Java libraries, and a host of updates to existing Java libraries. The new libraries are the Java Concurrency Utilities (JSR-166) which provide advanced multithreading controls, and the JVM Profiling API (JSR-163), which is a more powerful native profiling API called JVMTI.
The concurrency utilities provide advanced, high-level multithreading capabilities such as thread-safe queues, a thread task framework through executors, locks (including semaphores), timers, and various other synchronization primitives. For more details, explore the JavaDocs under java.lang.concurrent.
The JVMTI implementation includes Java Programming Language Instrumentation Services (JPLIS) which function at the bytecode level to enable analysis tools to add profiling, monitoring, and debugging where it is needed. This technique provides great flexibility and limits the interference of profiling and monitoring tools on a currently executing JVM. For more details, explore the JavaDocs under java.lang.instrument. A wide range of other existing Java libraries have received important updates, including the Utility package, Networking, Security, RMI, JDBC, and the CORBA libraries.

Desktop (UI)

J2SE 5.0 has taken some significant strides to address the traditionally slow startup time and heavy-weight memory footprint that has traditionally plagued Java desktop applications. The new version boasts enhanced font capabilities (especially to support localization and internationalization), many updates to Java Sound (broader platform support, optimized direct audio access, an improved and real-time Sequencer, etc.), hardware-accelerated rendering for Java 2D using OpenGL drivers, and even a new skin changing look and feel (Synth) and Theme (Ocean) for Swing.

Virtual Machine

Error Handling – Although the improvements are simple, the value is tremendous. Java developers now have the ability to capture stack traces as String objects and use them however they need to using the getStackTrace and Thread.getAllStackTraces, rather than being forced to send Stack Trace information to the console. Additionally, the HotSpot JVM has been updated to include a fatal error handler for running a user-supplied script or program if the JVM dies. Finally, the HotSpot JVM has been given a serviceability agent connector that permits monitoring and debugging tools to connect to a hung JVM or core file and extract relevant diagnostic data.

Management and Monitoring – From instrumentation (JPLIS) to Java Management Extensions (JMX) support, to support of remote access protocols and SNMP tools, management and monitoring have been greatly enhanced with J2SE 5.0. All of this is ready to use out of the box, supporting local and remote management and monitoring of a running JVM.

Performance and Scalability – A great deal of attention has been given to the subject of performance in this latest release of the core Java platform. Java 5 starts more quickly, leaves a smaller memory footprint, and offers enhanced scalability by enabling multiple JVMs to share read-only data. One really interesting enhancement is the ability to designate the role of a JVM as either a ‘client’ or a ‘server’. The JVM then automatically tunes itself to provide the optimum environment for the specified role, delivering enhanced performance, garbage collection, and thread prioritization.

Analysis of Java 5

Overall, J2SE 5.0 has really aimed to make developing Java software easier. From language features that save time and effort (generics, formatted I/O, metadata, varargs, etc.), to enhanced error handling, JVM management, performance and scalability, and many Java library updates to ease common developer headaches.
With the inclusion of generics, overhauled JVM, and emphasis upon performance and scalability of the platform, the Sun engineering team addressed all the major items on my list of desired improvements to the Java platform. The only other thing that I really wished I had seen with this release was an enhanced Java Reference API to support more object-oriented caching capabilities within the platform straight out of the box (rather than relying upon this value-add from external vendors).

Conclusion

Java has come a long way over the past nine years. The strides made in this new release of the Java platform will no doubt be significant for the viability of the platform. It is critical that Sun shows the industry that Java is still an innovative platform that is robust enough and flexible enough to meet the ever-changing climate of the Information Technology sector. If the industry takes a close look at Java 5, I believe they will see that this is, in fact, the case. Go Tiger – 1, 2, …5!

No comments: