February 05, 2004 | Category:

Java 1.5

Yesterday, the first beta of the long-awaited Java 1.5 finally went public. Sporting a large number of new features and classes, this new version will make every Java programmers life easier.

Firstly, there are the new types and constructs.

The new enumerated types have been in demand for a while, and work similarly to the typical C/C++ idiom. In terms of Java, they are being compared to public inner classes; encapsulated but accessible.

Auto-boxing takes away some of the hassle of casting primitive types to their respective wrapper classes. It should automatically create a reference, r, to the primitive, p, such that r.value() == p. Not a huge change, but it will help cut code.

Much bigger is the enhanced for loop. As part of the introduction of Generics – the new method to allow operations of objects of varying types safely – the new for loop will provide cleaner iteration over any Iterable class (pertinently, anything in the Collections framework). Instead of explicitly creating iterators and updating at each stage, a pseudo foreach syntax will be used. Example: for (String s : c). This will take each String S in c (most likely a collection), and perform the loop operations on each one. Very clean, very nice.

There are also some interesting new classes, both extending the old and starting from scratch.

The Collections framework has been updated in several areas. Queue provides an interface for holding Objects before processing. This has been implemented by, among several others, the PriorityQueue and SynchronousQueue classes. A more extensive list of the changes to Collections is available.

Other changes include:

  • Scanner class – a method for parsing primitives and Strings using regexes.
  • Removal of RMIC – No more need to compile RMI stub classes explicitly.
  • Improvements to garbage collection – It was a little lacking before.
  • The Concurrency Framework – Aiming to do for concurrent applications what the Collections framework did for data structures; providing a simple, consistent way of doing concurrency.
  • Improved XML handling – Supporting both SAX and DOM parsing.
  • Making JFrame.add() equivalent to JFrame.getContentPane().add() – a small, but simple enhancement.
  • Networking Enhancements – Improved support for various standards (including IPv6) and a minimal set of mandatory protocol handlers.

All in all, Java programming just got a lot simpler.