What's New in Java 6
Java 6, codenamed Mustang, was released on December 11, 2006. Sun renamed “J2SE” to “Java SE” and dropped “.0” from the version number, while the internal developer version remained 1.6.0. This release was developed under JSR 270.
Scripting
Java SE 6.0 added support for scripting languages. The scripting framework supports third-party script engines through a service discovery mechanism, and ships with a JavaScript engine based on Mozilla Rhino as the default, making it possible to call JavaScript from Java:
1 | import javax.script.*; |
Java Compiler API
Many applications dynamically generate and compile code at runtime, such as JSP web servers. Before Java SE 6.0, there were only two ways to dynamically generate code:
- Generate a temporary
.javafile and calljavacviaRuntime.exec()– quite inelegant - Hack into
javac‘s internals and use the Java interface – this worked but was undocumented, unsupported, and incompatible with third-party compilers
In fact, Sun had already provided a Java Compiler API in Java SE 5.0, but it was non-standard. In Java SE 6.0, the Java Compiler API was standardized:
1 | public class Compiler { |
JDBC 4.0
Key features of JDBC 4.0:
- New
javax.sql.DataSourceimplementations - Automatic JDBC driver loading – starting from Java SE 6.0, you no longer need to manually call
Class.forName(String)to load drivers;DriverManagerautomatically finds the appropriate JDBC driver when a connection is requested - New, more descriptive
SQLExceptionsubclasses - Introduction of the concept of wrapped JDBC objects, allowing applications to look up vendor-specific extensions in standard JDBC objects such as
Connections,Statement, andResultSets Statementevents that allow connection pools to listen forStatementclose and error events- Streaming API for
CallableStatement,PreparedStatement, andResultSet
Collection Framework Enhancements
New Interfaces
New Classes
- ArrayDeque
- ConcurrentSkipListSet
- ConcurrentSkipListMap
- LinkedBlockingDeque
- AbstractMap.SimpleEntry
- AbstractMap.SimpleImmutableEntry
Classes Implementing New Interfaces
New Methods
Jar & Zip Enhancements
Two new compression streams were added:
Reflection Enhancements
In Java SE 5.0, the return values and parameters of reflection-related methods in java.lang.Class were generified:
- getInterfaces()
- getClasses()
- getConstructors()
- getMethod(String, Class…)
- getConstructor(Class…)
- getDeclaredClasses()
- getDeclaredConstructors()
- getDeclaredMethod(String, Class…)
- getDeclaredConstructor(Class…)
Code using these methods would produce warnings during compilation. To eliminate these warnings, Java SE 6.0 added generic types to the return values and parameter types of these methods.
Serialization Enhancements
- Added java.io.ObjectStreamClass.lookupAny(Class) for obtaining
ObjectStreamClassinstances of non-serializable classes - Fixed a delayed GC bug caused by
ObjectOutputStreamandObjectInputStreamholding strong references to serializable classes and subclasses during serialization, potentially indefinitely delaying garbage collection of theClassLoaderthat defined those classes
VM Enhancements
- Added DTrace probes
- Added parallel compaction on top of the existing parallel GC. In Java SE 5.0, the parallel collector performed young generation collection in parallel, but full GC was single-threaded. In Java SE 6.0, parallel compaction significantly improved GC performance by executing full GC in parallel
- Enhanced the CMS (Concurrent Mark Sweep) collector – -XX:+ExplicitGCInvokesConcurrent enables
System.gc()orRuntime.getRuntime().gc()to run concurrently - Increased the default young generation size from 4MB to 16MB
- Increased the proportion of total heap used for the young generation from 1/15 to 1/7
- Survivor spaces are now enabled by default with increased default sizes (previously, the CMS collector disabled survivor spaces by default)
- The CMS collector uses multiple threads for concurrent marking on multi-processor platforms (previous versions used only a single thread)
Instrumentation Enhancements
- Support for class file retransformation
- Support for native method instrumentation
- Support for appending JARs to the
ClassLoadersearch path
JVM TI (Tool Interface)
Java SE 6.0 enhanced the JVM TI:
- Support for transformation of class files
- Enhanced heap walking support
- allows access to primitive values (the value of Strings, arrays, and primitive fields)
- allows the tag of the referrer to be set, thus enabling more efficient localized reference graph building
- provides more extensive filtering abilities
- is extensible, allowing abilities to grow in future versions of JVM TI
- More class information
- Support for instrumenting native methods
- Enhanced support for instrumentation under the system class loader
- Support for early return from a method
- Monitor stack depth information
- Support for resource exhaustion notification
For more details, see: https://www.oracle.com/java/technologies/javase/features.html
- Blog Link: https://johnsonlee.io/2021/05/07/java-6-new-features.en/
- Copyright Declaration: 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
