Java 2 Platform Standard Edition (J2SE) 5.0 ("Tiger") is the next major revision to the Java platform and language; it is currently slated to contain 15 component JSRs with nearly 100 other significant updates developed through the Java Community Process (JCP). NOTE: The external version number of this release is 5.0 and its internal version number is 1.5.0, as described at J2SE Naming and Versioning. With so many exciting changes in this release, you may be wondering where you should start. As in previous releases, the comprehensive list of all changes is available in the Release notes guide. This article, from the J2SE team, will take you through the major changes so that you have a grasp of what J2SE 5.0 has to offer, before diving into the API docs. The J2SE 5.0 release is focused along certain key themes: There are a small number of features that are just as important but didn't neatly fit in with the themes; they are listed at the end: Ease of DevelopmentYou may have already seen reports about some of the new Java Language changes that comprise the Ease of Development theme. The changes include generic types, metadata, autoboxing, an enhanced for loop, enumerated types, static import, C style formatted input/output, variable arguments, concurrency utilities, and simpler RMI interface generation. JSR-201 contains four of these language changes; enhanced for loop, enumerated types, static import and autoboxing; JSR-175 specifies the new metadata functionality, while JSR-14 details generic types. The new default language specification implemented by the javac compiler is version 5.0, also known as 1.5, so you do not need to supply the option -source 1.5 (as required in beta1). MetadataThe metadata feature in J2SE 5.0 provides the ability to associate additional data alongside Java classes, interfaces, methods, and fields. This additional data, or annotation, can be read by the javac compiler or other tools, and depending on configuration can also be stored in the class file and can be discovered at runtime using the Java reflection API. One of the primary reasons for adding metadata to the Java platform is to enable development and runtime tools to have a common infrastructure and so reduce the effort required for programming and deployment. A tool could use the metadata information to generate additional source code, or to provide additional information when debugging. In beta2 we are pleased to announce the availability of an annotation processing tool called apt. Apt includes a set of new reflective APIs and supporting infrastructure to process program annotations. The apt reflective APIs provide a build-time, source-based, read-only view of program structure which cleanly models the Java programming language's type system. First, apt runs annotation processors that can produce new source code and other files. Next, apt can cause compilation of both original and generated source files, easing development. For more information on apt refer to the apt guide. In the following example code you can additionally create an AnnotationFactory
processor for apt to generate code or documentation when finding the
With a metadata processing tool, many repetitive coding steps could be reduced to a concise metadata tag. For example, the remote interface required when accessing a JAX-RPC service implementation could be implemented as follows: Before
After
Generic TypesGeneric types have been widely anticipated by the Java Community and are now
part of J2SE 5.0. One of the first places to see generic types in action is
the Collections API. The Collections API provides common functionality like
The cast to The same example with the generified Collections library is written as follows:
The user of a generified API has to simply declare the type used at compile
type using the <> notation. No casts are needed and in this example trying
to add a Generic types therefore enable an API designer to provide common functionality that can be used with multiple data types and which also can be checked for type safety at compile time. Designing your own Generic APIs is a little more complex that simply using
them. To get started look at the Autoboxing and Auto-Unboxing of Primitive TypesConverting between primitive types, like int, boolean, and their equivalent Object-based counterparts like Integer and Boolean, can require unnecessary amounts of extra coding, especially if the conversion is only needed for a method call to the Collections API, for example. The autoboxing and auto-unboxing of Java primitives produces code that is
more concise and easier to follow. In the next example an Before
After
Enhanced for LoopThe Before
After
Enumerated TypesThis type provides enumerated type when compared to using static final constants.
If you have previously used the identifier enum in your own application, you
will need to adjust the source when compiling with
Static ImportThe static import feature, implemented as "import static", enables you to
refer to static constants from a class without needing to inherit from it.
Instead of
Formatted OutputDevelopers now have the option of using printf-type functionality to generate formatted output. This will help migrate legacy C applications, as the same text layout can be preserved with little or no change. Most of the common C printf formatters are available, and in addition some
Java classes like
Formatted InputThe scanner API provides basic input functionality for reading data from the system console or any data stream. The following example reads a String from standard input and expects a following int value. The Scanner methods like
VarargsThe varargs functionality allows multiple arguments to be passed as parameters to methods. It requires the simple ... notation for the method that accepts the argument list and is used to implement the flexible number of arguments required for printf.
Concurrency UtilitiesThe concurrency utility library, led by Doug Lea in JSR-166, is a special release of the popular concurrency package into the J2SE 5.0 platform. It provides powerful, high-level thread constructs, including executors, which are a thread task framework, thread safe queues, Timers, locks (including atomic ones), and other synchronization primitives. One such lock is the well known semaphore. A semaphore can be used in the
same way that
rmic -- The RMI CompilerYou no longer need to use rmic, the rmi compiler tool, to generate most remote interface stubs. The introduction of dynamic proxies means that the information normally provided by the stubs can be discovered at runtime. See the RMI release notes for more information. Scalability and PerformanceThe 5.0 release promises improvements in scalability and performance, with a new emphasis on startup time and memory footprint, to make it easier to deploy applications running at top speed. One of the more significant updates is the introduction of class data sharing in the HotSpot JVM. This technology not only shares read-only data between multiple running JVMs, but also improves startup time, as core JVM classes are pre-packed. Performance ergonomics are a new feature in J2SE 5.0. This means that if you have been using specialized JVM runtime options in previous releases, it may be worth re-validating your performance with no or minimal options. Monitoring and ManageabilityMonitoring and Manageability is a key component of RAS (Reliability, Availability, Serviceability) in the Java platform. The J2SE 5.0 release provides comprehensive monitoring and management support: instrumentation to observe the Java virtual machine, Java Management Extensions (JMX) framework, and remote access protocols. All this is ready to be used out-of-the-box. (See the Management and Monitoring release notes for more details.) The JVM Monitoring & Management API specifies a comprehensive set of instrumentation of JVM internals to allow a running JVM to monitored. This information is accessed through JMX (JSR-003) MBeans and can accessed locally within the Java address space or remotely using the JMX remote interface (JSR-160) and through industry-standard SNMP tools. One of the most useful features is a low memory detector. JMX MBeans can notify registered listeners when the threshold is crossed, see javax.management and java.lang.management for details. J2SE 5.0 provides an easy way to enable out-of-the-box remote management of JVM and an application (see Out-of-the-Box for details). For example, to start an application to be monitorable by jconsole in the same local machine, use the following system property:
and to monitor it remotely through JMX without authentication:
For an idea of how easy the new API is to use, the following reports the detailed usage of the memory heaps in the HotSpot JVM.
New JVM Profiling API (JSR-163)The release also contains a more powerful native profiling API called JVMTI. This API has been specified through JSR-163 and was motivated by the need for an improved profiling interface. However, JVMTI is intended to cover the full range of native in-process tools access, which in addition to profiling, includes monitoring, debugging and a potentially wide variety of other code analysis tools. The implementation includes a mechanism for bytecode instrumentation, Java Programming Language Instrumentation Services (JPLIS). This enables analysis tools to add additional profiling only where it is needed. The advantage of this technique is that it allows more focused analysis and limits the interference of the profiling tools on the running JVM. The instrumentation can even be dynamically generated at runtime, as well as at class loading time, and pre-processed as class files. The following example creates an instrumentation hook that can load a modified
version of the class file from disk. To run this test, start the JRE with
Improved Diagnostic AbilityGenerating Stack traces has been awkward if no console window has been available.
Two new APIs,
The HotSpot JVM includes a fatal error handler that can run a user-supplied script or program if the JVM aborts. A debug tool can also connect to a hung JVM or core file using the HotSpot JVM serviceability agent connector.
Desktop ClientThe Java Desktop client remains a key component of the Java platform and as such has been the focus of many improvements in J2SE 5.0. This Beta release contains some of the early improvements in startup time and memory footprint. Not only is the release faster, but the Swing toolkit enjoys a fresh new theme called Ocean. And by building on the updates in J2SE 1.4.2, there are further improvements in the GTK skinnable Look and Feel and the Windows XP Look and Feel.
Linux and Solaris users, and new in beta2, Windows users, who have the latest OpenGL drivers and select graphic cards can get native hardware acceleration from Java2D using the following runtime property:
The Linux release also has the fast X11 toolkit, called XAWT, enabled by default. If you need to compare against the motif version you can use the following system property:
(the X11 toolkit is called sun.awt.X11.XToolkit) The X11 Toolkit also uses the XDnD protocol so you can drag-and-drop simple components between Java and other applications like StarOffice or Mozilla. Miscellaneous FeaturesCore XML SupportJ2SE 5.0 introduces several revisions to the core XML platform, including XML 1.1 with Namespaces, XML Schema, SAX 2.0.2, DOM Level 3 Support and XSLT with a fast XLSTC compiler. In addition to the core XML support, future versions of the Java Web Services Developer Pack will deliver the latest web services standards: JAX-RPC & SAAJ (WSDL/SOAP), JAXB, XML Encryption, and Digital Signature and JAXR for registries. Supplementary Character Support32-bit supplementary character support has been carefully added to the platform as part of the transition to Unicode 4.0 support. Supplementary characters are encoded as a special pair of UTF16 values to generate a different character, or codepoint. A surrogate pair is a combination of a high UTF16 value and a following low UTF16 value. The high and low values are from a special range of UTF16 values. In general, when using a String or sequence of characters, the core API libraries will transparently handle the new supplementary characters for you. However, as the Java "char" still remains at 16 bits, the very few methods that used char as an argument now have complementary methods that can accept an int value which can represent the new larger values. The Character class in particular has additional methods to retrieve the current character and the following character in order to retrieve the supplementary codepoint value as below:
See the Unicode section in Character for more details. JDBC RowSetsThere are five new JDBC RowSet class implementations in this release. Two
of the most valuable ones are The following code fragment shows how easy it is to create and use a
ReferencesNew Language Features for Ease of Development in the Java 2 Platform Standard Edition 5.0: http://java.sun.com/features/2003/05/bloch_qa.html Tiger Component JSRs003 Java Management Extensions (JMX) Specification http://jcp.org/en/jsr/detail?id=3 013 Decimal Arithmetic Enhancement http://jcp.org/en/jsr/detail?id=13 014 Add Generic Types To The Java Programming Language http://jcp.org/en/jsr/detail?id=14 028 Java SASL Specification http://jcp.org/en/jsr/detail?id=28 114 JDBC Rowset Implementations http://jcp.org/en/jsr/detail?id=114 133 Java Memory Model and Thread Specification Revision http://jcp.org/en/jsr/detail?id=133 160 Java Management Extensions (JMX) Remote API 1.0 http://jcp.org/en/jsr/detail?id=160 163 Java Platform Profiling Architecture http://jcp.org/en/jsr/detail?id=163 166 Concurrency Utilities http://jcp.org/en/jsr/detail?id=166 174 Monitoring and Management Specification for the Java Virtual Machine http://jcp.org/en/jsr/detail?id=174 175 A Metadata Facility for the Java Programming Language http://jcp.org/en/jsr/detail?id=175 200 Network Transfer Format for Java Archives http://jcp.org/en/jsr/detail?id=200 201 Extending the Java Programming Language with Enumerations, Autoboxing, Enhanced for Loops and Static Import http://jcp.org/en/jsr/detail?id=201 204 Unicode Supplementary Character Support http://jcp.org/en/jsr/detail?id=204 206 Java API for XML Processing (JAXP) 1.3 http://jcp.org/en/jsr/detail?id=206 | |||||||||||||||||||||||||||||||||||||||||||
![]() | ![]() |