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 http://java.sun.com/j2se/1.5.0. 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.

    Example:

    For (Iterator i = lstList.iterator(); i.hasNext();){ Integer value = (Integer)i.next; 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]); 

    Or:

     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 java.lang.management.*;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.

devx-admin

devx-admin

Share the Post:
Poland Energy Future

Westinghouse Builds Polish Power Plant

Westinghouse Electric Company and Bechtel have come together to establish a formal partnership in order to design and construct Poland’s inaugural nuclear power plant at

EV Labor Market

EV Industry Hurting For Skilled Labor

The United Auto Workers strike has highlighted the anticipated change towards a future dominated by electric vehicles (EVs), a shift which numerous people think will

Soaring EV Quotas

Soaring EV Quotas Spark Battle Against Time

Automakers are still expected to meet stringent electric vehicle (EV) sales quotas, despite the delayed ban on new petrol and diesel cars. Starting January 2023,

Affordable Electric Revolution

Tesla Rivals Make Bold Moves

Tesla, a name synonymous with EVs, has consistently been at the forefront of the automotive industry’s electric revolution. The products that Elon Musk has developed

Poland Energy Future

Westinghouse Builds Polish Power Plant

Westinghouse Electric Company and Bechtel have come together to establish a formal partnership in order to design and construct Poland’s inaugural nuclear power plant at the Lubiatowo-Kopalino site in Pomerania.

EV Labor Market

EV Industry Hurting For Skilled Labor

The United Auto Workers strike has highlighted the anticipated change towards a future dominated by electric vehicles (EVs), a shift which numerous people think will result in job losses. However,

Soaring EV Quotas

Soaring EV Quotas Spark Battle Against Time

Automakers are still expected to meet stringent electric vehicle (EV) sales quotas, despite the delayed ban on new petrol and diesel cars. Starting January 2023, more than one-fifth of automobiles

Affordable Electric Revolution

Tesla Rivals Make Bold Moves

Tesla, a name synonymous with EVs, has consistently been at the forefront of the automotive industry’s electric revolution. The products that Elon Musk has developed are at the forefront because

Sunsets' Technique

Inside the Climate Battle: Make Sunsets’ Technique

On February 12, 2023, Luke Iseman and Andrew Song from the solar geoengineering firm Make Sunsets showcased their technique for injecting sulfur dioxide (SO₂) into the stratosphere as a means

AI Adherence Prediction

AI Algorithm Predicts Treatment Adherence

Swoop, a prominent consumer health data company, has unveiled a cutting-edge algorithm capable of predicting adherence to treatment in people with Multiple Sclerosis (MS) and other health conditions. Utilizing artificial

Personalized UX

Here’s Why You Need to Use JavaScript and Cookies

In today’s increasingly digital world, websites often rely on JavaScript and cookies to provide users with a more seamless and personalized browsing experience. These key components allow websites to display

Geoengineering Methods

Scientists Dimming the Sun: It’s a Good Thing

Scientists at the University of Bern have been exploring geoengineering methods that could potentially slow down the melting of the West Antarctic ice sheet by reducing sunlight exposure. Among these

why startups succeed

The Top Reasons Why Startups Succeed

Everyone hears the stories. Apple was started in a garage. Musk slept in a rented office space while he was creating PayPal with his brother. Facebook was coded by a

Bold Evolution

Intel’s Bold Comeback

Intel, a leading figure in the semiconductor industry, has underperformed in the stock market over the past five years, with shares dropping by 4% as opposed to the 176% return

Semiconductor market

Semiconductor Slump: Rebound on the Horizon

In recent years, the semiconductor sector has faced a slump due to decreasing PC and smartphone sales, especially in 2022 and 2023. Nonetheless, as 2024 approaches, the industry seems to

Elevated Content Deals

Elevate Your Content Creation with Amazing Deals

The latest Tech Deals cater to creators of different levels and budgets, featuring a variety of computer accessories and tools designed specifically for content creation. Enhance your technological setup with

Learn Web Security

An Easy Way to Learn Web Security

The Web Security Academy has recently introduced new educational courses designed to offer a comprehensible and straightforward journey through the intricate realm of web security. These carefully designed learning courses

Military Drones Revolution

Military Drones: New Mobile Command Centers

The Air Force Special Operations Command (AFSOC) is currently working on a pioneering project that aims to transform MQ-9 Reaper drones into mobile command centers to better manage smaller unmanned

Tech Partnership

US and Vietnam: The Next Tech Leaders?

The US and Vietnam have entered into a series of multi-billion-dollar business deals, marking a significant leap forward in their cooperation in vital sectors like artificial intelligence (AI), semiconductors, and

Huge Savings

Score Massive Savings on Portable Gaming

This week in tech bargains, a well-known firm has considerably reduced the price of its portable gaming device, cutting costs by as much as 20 percent, which matches the lowest

Cloudfare Protection

Unbreakable: Cloudflare One Data Protection Suite

Recently, Cloudflare introduced its One Data Protection Suite, an extensive collection of sophisticated security tools designed to protect data in various environments, including web, private, and SaaS applications. The suite

Drone Revolution

Cool Drone Tech Unveiled at London Event

At the DSEI defense event in London, Israeli defense firms exhibited cutting-edge drone technology featuring vertical-takeoff-and-landing (VTOL) abilities while launching two innovative systems that have already been acquired by clients.

2D Semiconductor Revolution

Disrupting Electronics with 2D Semiconductors

The rapid development in electronic devices has created an increasing demand for advanced semiconductors. While silicon has traditionally been the go-to material for such applications, it suffers from certain limitations.

Cisco Growth

Cisco Cuts Jobs To Optimize Growth

Tech giant Cisco Systems Inc. recently unveiled plans to reduce its workforce in two Californian cities, with the goal of optimizing the company’s cost structure. The company has decided to

FAA Authorization

FAA Approves Drone Deliveries

In a significant development for the US drone industry, drone delivery company Zipline has gained Federal Aviation Administration (FAA) authorization, permitting them to operate drones beyond the visual line of

Mortgage Rate Challenges

Prop-Tech Firms Face Mortgage Rate Challenges

The surge in mortgage rates and a subsequent decrease in home buying have presented challenges for prop-tech firms like Divvy Homes, a rent-to-own start-up company. With a previous valuation of

Lighthouse Updates

Microsoft 365 Lighthouse: Powerful Updates

Microsoft has introduced a new update to Microsoft 365 Lighthouse, which includes support for alerts and notifications. This update is designed to give Managed Service Providers (MSPs) increased control and

Website Lock

Mysterious Website Blockage Sparks Concern

Recently, visitors of a well-known resource website encountered a message blocking their access, resulting in disappointment and frustration among its users. While the reason for this limitation remains uncertain, specialists