Java 5: Unleash the Tiger on Your Next Project Java 5 Features Kyle Gabhart
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 had to 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 to 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 for 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.