Tiger Stripes: Get Ready to Purr Over J2SE 5.0

Tiger Stripes: Get Ready to Purr Over J2SE 5.0

t has been a little while since Java got a refresh, and with the Java Community Process churning out updates in the form of new JSRs by the hundred, it is high time that the standard or reference API got updated. Well, the time has come, and version 5.0 (codenamed ‘Tiger’) is currently in its second beta phase. Technically speaking, Tiger is the 1.5 version of Java, but Sun Microsystems announced at the 2004 JavaOne developers conference that this version would start fresh with a ‘5.0’ number. You can download the beta from This article will cover the major functional improvements and let you know what to expect from ‘Tiger.’

The improvements to the API can be grouped into the following major themes:

  • Developer productivity
  • Scalability and performance
  • Monitoring and manageability
  • Improved desktop

Downloading and Installation

Figure 1. Custom Setup for JDK 5: As you might expect, the first part of the install process requires you to identify the portions to install.

Before I begin running through the specific features of the new version, I’ll run through the process of unpacking and installing the download from Sun Microsystems. This section is based on an installation of beta 2 on a machine running Windows XP Service Pack 2. After accepting all relevant licenses, your first screen on the wizard is shown in Figure 1. It looks like a Microsoft Office installation.

Configure what you want to install (I chose everything) and hit Next; the installer launches, copying the files and setting up the relevant paths. It is painless and very straightforward. At the end, just when you are expecting the installation to be done, you get another dialog (see Figure 2). This is of course the JRE setup, but it was a little surprising to get a separate installation. Perhaps this is something that will go away upon release.

After installation, you’ll have the JDK and the JRE installed, and a new Control Panel applet to boot. This applet is shown in Figure 3.

Figure 2. JRE Setup: You have to do a separate install approval screen in order to unpack the JRE.
Figure 3. Java Control Panel: When your installation is complete, you get a new Control Panel for configuring your Java VM.

Ease of Development
Many of the language changes are designed to improve developer productivity. These include the addition of generics (similar to C++ templates), metadata, autoboxing, enhanced looping, enumerated types, static imports, variable arguments, and many more. You can see a lot of these in detail in JSR-201, JSR-175, and JSR-14.

  • Generics
    Support for generics has become an important area of language competition lately. Microsoft has added it to .NET 2.0, which has just entered beta, while Sun is quickly adding it to Java in version 5. In short, generics is about allowing you to abstract common functionality across multiple data types without rewriting that functionality for each type that you use.

    For example, the following code is used today:

    ArrayList lstList = new ArrayList();lstList.add(0, new Integer(42));int total = ((Integer)list.get(0)).intValue();

    In this case, the developer has to understand that list will contain Integers, and use the (Integer) cast when pulling something out. Type mismatches cannot be picked up at compile time as the ArrayList holds Object types, so there would be no type mismatch problems. Referring to the wrong type when pulling information out of the list could lead to an ugly run-time error.

    When using generics, your code would look something like this:

    ArrayList lstList = new ArrayList();lstList.add(0,new Integer(42));int total = list.get(0).intValue();

    The use of the generic means that the type of the list is now declared using so its types will be strongly checked at compile time. This means that your code is less prone to casting problems or type mismatches at run time, which can only be a good thing!

  • Metadata
    This feature gives you the facility to describe your Java classes, interfaces, methods, and fields with data annotations that can be read by the compiler or other tools and can be used to aid in the integration of your code with other systems. For example, an IDE can query the metadata associated with one of your classes to understand what the class is, and potentially generate code from that. In other words, you could, for example build a Web service bean or EJB and attribute this as being a Web service. Theoretically an IDE could ‘detect’ that it is a Web service from the metadata and automatically generate stubs and proxies for calling that Web service, eliminating manual steps.
  • Auto-Boxing of Data Primitives
    While this may not get the attention that generics and metadata are getting, this feature is amazingly useful, particularly for new developers (although it might make computer scientists a little skittish). It is simply an automatic, compile-time, transition between simple data types and their object-oriented big brothers. For example, with auto-boxing you can interchange int and Integer without breaking a sweat. This has, in the past, led to a lot of unnecessary coding and casting, and should now make code more readable. Those who love to question prospective job candidates about the difference between boolean and Boolean during interviews will have to look somewhere else for their trick questions!

    Consider the listings above used to demonstrate generics. As the list was defined as being a list of Integer types, when adding to the list you had to cast the value ’42’ (which is an int) to an Integer for it to be accepted.

    lstList.add(0, new Integer(42)); 

    with auto-boxing, java is smart enough to know what you want when you use

    lstList.add(0, 42); 

    making your code a whole lot more readable.

  • Enhanced Looping
    There is a new construct for looping that certainly makes your code shorter, although it is debatable as to whether or not it makes your code more readable. It removes the concept of an explicit iterator when coding a loop.


    For (Iterator i = lstList.iterator(); i.hasNext();){ Integer value = (Integer); Do Whatever

    }Now becomes:

    For (Integer i : lstList){ Do whatever } 

    This kind of looping is nice because it logically places what you are interested in into the loop, instead of having to sidestep into Iterators. On the downside, the construct (Integer I : list) is a little obscure and may take a little getting used to.

  • Enumerated Types
    Long a beloved feature of C++, this is now available in Java so that you can have an enumeration of a data type instead of a long list of constants.
    Public enum maritalStatus{ single, married, divorced, widowed };

    Instead of:

    Static Final STATUS_SINGLE = 0;Static Final STATUS_MARRIED = 1;etc
  • Variable Arguments
    This language enhancement helps you write overloads for functions that accept many different parameter sets. And as you might imagine, it is particularly useful when you have lots of different parameter sets. For example, if you want the same function to have instances that accept 1, 2, or 3 parameters, you don’t have to write three overloads). It uses the ‘…’ notation to accept the argument.

    For example:

    int nGetTotalVotes(Object … nStates){	for(int i=0; i

    Would allow you to call this function with calls like:

     X = nGetTotalVotes( State[FLORIDA], State[WASHINGTON]); 


     X = nGetTotalVotes( State[NY], State[CA], State[MA], State[NH]); 

    Where the list of parameters can change drastically without you having to worry about major overloading headaches.

Scalability and Performance
There are a number of areas where Sun has been tweaking Java to improve performance, emphasizing startup time and memory footprint. It has also introduced the concept of class data sharing in the JVM, where read-only data may be shared between multiple running JVMs, which is great for programs that use multiple JVMs, but it also means that many core JVM classes are pre-loaded by the first instance of the JVM.

Monitoring and Manageability
Java Management Extensions (JMX) evolved from JSR-003. They are tools that allow the JVM and your applications to be monitored using the JMX Remote Interface (JMXRI, JSR-160) or industry standard SNMP tools. These come with a full API so that you can inspect management characteristics such as the amount of free memory or the CPU load within your own applications. For example, the code snippet below shows how you can use the MemoryPoolMXBean type from the management API to output information about memory usage.

import*;import java.util.*;public class MemTest {  public static void main(String args[]) {    List pools =               ManagementFactory.getMemoryPoolMXBeans();    for (MemoryPoolMXBean p: pools) {      System.out.println("Memory type="+p.getType()+" Memory            Usage="+p.getUsage());    }  }}

Another useful API class set is one which helps you get around stack traces. It can be very awkward to get a stack trace if no console window is readily available. Anybody who has tried to figure out why a problem is occurring on a distant customer site while the application works nicely on your development platform will know exactly what I mean. Tiger gives you a getStackTrace and a getAllStackTraces class that will allow you to roll your own output logger for handling errors or other functionality.

Improved Desktop
Java has been much maligned as a platform for building desktop applications. With the JVM wars of the past behind us and with new initiatives such as SWT giving developers better methodologies for success, Java on the desktop is making a comeback. The emergence of Linux as a contender to Windows for the corporate desktop has helped to fuel this trend.

It should come as no surprise then that the Java SDK is evolving, and its native look and feel themes are getting closer and closer to their Windows-native counterparts. As an example, Figure 4 shows the Windows common dialog box, rendered in both J2SE and Microsoft Office 2003. Can you spot which side is which?

Figure 4. Which Is Which? : One of these dialog boxes comes from Java/Swing and the other is native Windows.

The eagle-eyed among you will see that the Java one is on the left. The Java icon in the top right-hand corner is the only dead giveaway. Other than a few differences with the icons and slightly different shades of color, there isn't much to distinguish between the native GUI and the Java one. Incidentally, the Java common dialog is much faster when you have a machine that has network shares, as it doesn't attempt to preauthenticate against those shares before you can do anything. So, in a case such as this one where you are looking for files on your hard drive, Java is orders of magnitude faster than the standard Windows dialog used by Microsoft Office!

It's been a long time coming, but the new version of the Java SDK will be worth the wait. Language enhancements mostly make your code more readable, but more importantly bring more compiler checking into common tasks, reducing run-time errors in typical code. While some of the language enhancements are making Java look more C++ like and therefore a little more complicated, on the whole it appears to succeed in giving power without sacrificing readability and learning curve. Features such as auto-boxing are great for new developers in particular.

Add to this the performance enhancements, namely the loading and memory management of the VM, as well as the manageability extensions and it looks like a run-time winner too. The biggest challenge to the widespread adoption of the SE, particularly for enterprise users, is the poisoned well of desktop VM incompatibility and reduced user experience. This came about from incompatibilities between VMs from Microsoft and Sun and from the lowest-common-denominator approach of the original Java 1.0. For example, under Java 1.0 only one mouse button was supported because the Macintosh only supported one button, and should the VM support more than one, the portability of applications would be lost. This led to a reduced experience relative to writing in native code. Put simply, J2SE 1.5 is going to give current Java developers much to be grateful for and will ensure the language remains competitive with C#, C++, and any other modern-day programming languages.


About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist