JDK-1.6 features

Java SE 6 API provides bi-directional collection access. New collection interfaces includes Deque, NavigableSet, NavigableMap.
  • Deque: A linear collection that supports element insertion and removal at both ends. The name deque is short for "double ended queue".
  • This interface defines methods to access the elements at both ends of the deque. Methods are provided to insert, remove, and examine the element.
  • Each of these methods exists in two forms: one throws an exception if the operation fails, the other returns a special value (either null or false, depending on the operation)
  • New class” Console” is added and it contains methods to access a character-based console device.
  • The readPassword()methods disable echoing thus they are suitable for retrieval of sensitive data such as passwords.
  • The method System.console ()returns the unique console associated with the Java Virtual Machine.
  • Increased Developer Productivity
  • JFC and Swing integration with desktop by using Windows API.
  • Java 2D integration with desktop such as using desktop anti-aliasing font settings
  • Splash screen direct support and can be shown before JVM started
  • System tray support with ability to add icons, tool tips, and pop-up menus to the Windows or any other system tray (such as Gnome).
  • Native platform Security (GSS/Kerberos) integration.
  • Java Authentication and Authorization Service (JAAS) login module that employs LDAP authentication
  • New Smart Card I/O API
  • The Java API for XML Processing (JAXP) enables applications to parse, transform, validate and query XML documents using an API that is independent of a particular XML processor implementation. JAXP provides a pluggability layer to enable vendors to provide their own implementations without introducing dependencies in application code. Using this software, application and tool developers can build fully-functional XML-enabled Java applications for e-commerce, application integration, and web publishing.
  • The Java Platform, Standard Edition version 6.0 includes JAXP 1.4. JAXP 1.4 is a maintenance release of JAXP 1.3 with support for the Streaming API for XML (StAX).
Java SE 6 includes several enhancements to the Java Database Connectivity (JDBC) API. These enhancements will be released as JDBC version 4.0. The main objectives of the new JDBC features are to provide a simpler design and better developer experience
  • The major features added in JDBC 4.0 include:
  • 1.Auto-loading of JDBC driver class
  • 2.Connection management enhancements
  • 3.Support for RowId SQL type
  • 4.DataSet implementation of SQL using Annotations
  • 5.SQL exception handling enhancements
  • In JDBC 4.0, we no longer need to explicitly load JDBC drivers using Class.forName().When the method getConnection is called, the DriverManager will attempt to locate a suitable driver from among the JDBC drivers that were loaded at initialization and those loaded explicitly using the same class loader as the current application.
  • The DriverManager methods getConnection and getDrivers have been enhanced to support the Java SE Service Provider mechanism (SPM).
  • According to SPM, a service is defined as a well-known set of interfaces and abstract classes, and a service provider is a specific implementation of a service.
  • It also specifies that the service provider configuration files are stored in the META-INF/services directory. JDBC 4.0 drivers must include the file META-INF/services/java.sql.Driver.
  • This file contains the name of the JDBC driver’s implementation of java.sql.Driver. For example, to load the JDBC driver to connect to a Apache Derby database, the META-INF/services/java.sql.
  • Driver file would contain the following entry:
  • org.apache.derby.jdbc.EmbeddedDriver
    We can simply call:
    Connection conn =
    DriverManager.getConnection(jdbcUrl, jdbcUser, jdbcPassword);In JDBC 4.0, we don’t need the Class.forName() line.

  • Connection management enhancements:
  • Prior to JDBC 4.0, we relied on the JDBC URL to define a data source connection.
  • Now with JDBC 4.0, we can get a connection to any data source by simply supplying a set of parameters (such as host name and port number) to a standard connection factory mechanism.
  • New methods were added to Connection and Statement interfaces to permit improved connection state tracking and greater flexibility when managing Statement objects in pool environments. The metadata facility (JSR-175) is used to manage the active connections.
  • We can also get metadata information, such as the state of active connections, and can specify a connection as standard (Connection, in the case of stand-alone applications), pooled (PooledConnection), or even as a distributed connection (XAConnection) for XA transactions. Note that we don’t use the XAConnection interface directly. It’s used by the transaction manager inside a Java EE application server such as WebLogic, WebSphere, or JBoss.
  • The RowID interface was added to JDBC 4.0 to support the ROWID data type which is supported by databases such as Oracle and DB2. RowId is useful in cases where there are multiple records that don’t have a unique identifier column and you need to store the query output in a Collection (such Hashtable) that doesn’t allow duplicates. We can use ResultSet’s getRowId() method to get a RowId and PreparedStatement’s setRowId() method to use the RowId in a query..
  • An important thing to remember about the RowId object is that its value is not portable between data sources and should be considered as specific to the data source when using the set or update methods in PreparedStatement and ResultSet respectively. So, it shouldn’t be shared between different Connection and ResultSet objects.
  • The JDBC 4.0 specification leverages annotations (added in Java SE 5) to allow developers to associate a SQL query with a Java class without writing a lot of code to achieve this association. Also, by using the Generics (JSR 014) and metadata (JSR 175) APIs, we can associate the SQL queries with Java objects specifying query input and output parameters. We can also bind the query results to Java classes to speed the processing of query output. We don’t need to write all the code we usually write to populate the query result into a Java object. There are two main annotations when specifying SQL queries in Java code: Select and Update.
  • Here’s an example of Select annotation to get all the active loans from the loan database:
  • interface LoanAppDetailsQuery extends BaseQuery {
    							@Select(“SELECT * FROM LoanDetais where LoanStatus = ‘A’”)
    							DataSet getAllActiveLoans();
    								}
    							public DataSet getAllActiveLoans() throws Exception {
    							// Get Connection
    							Connection conn = getConnection();
    							LoanAppDetailsQuery query = null;
    							DataSet loanDetails = null;
    							query = QueryObjectFactory.createQueryObject(
    							LoanAppDetailsQuery.class, conn);
    							loanDetails = query.getAllActiveLoans();
    							return loanDetails;
    									}
    							
  • Example of Update annotation:
  • interface LoanAppDetailsQuery extends BaseQuery {
    								@Update(sql=”update LoanDetails set LoanStatus = ?1
    							where loanId = ?2″)
    							boolean updateLoanStatus(String loanStatus, int loanId);
    								}
    							
  • Increased Developer Productivity
  • Support for causal relationships
  • Support for enhanced for-each loop
  • Ex1: We can use getNextException() method in SQLException to iterate through the exception chain. Here’s some sample code to process SQLException causal relationships:
  • 
    						catch(SQLException ex) {
    						while(ex != null) {
    						LOG.error(“SQL State:” + ex.getSQLState());
    						LOG.error(“Error Code:” + ex.getErrorCode());
    						LOG.error(“Message:” + ex.getMessage());
    					Throwable t = ex.getCause();
    						while(t != null) {
    					LOG.error(“Cause:” + t);		
    					t = t.getCause();
    						}
    					ex = ex.getNextException();
    							}
    								}
    							
  • Ex2:code snippet showing the enhanced for-each loop feature added in SQLException.
  • 
    						catch(SQLException ex) {
    						for(Throwable e : ex ) {
    					LOG.error(“Error occurred: ” + e);
    						}
    							}