Google

Sunday, December 03, 2006

Whats new in Java SE 6(MUSTANG)

Java Platform, Standard Edition (Java SE) version 6 (code name Mustang), is currently in its second beta release. 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. This article provides an overview of the JDBC 4.0 enhancements and what benefits they offer to enterprise Java developers. We will explore the new JDBC features with the help of a sample loan processing application using Apache Derby as the back-end database.

Java SE 6.0

The Java SE 6.0 release mainly aims at providing compatibility, stability, and quality. There are several interesting enhancements in this release, especially in the areas of monitoring and management (JMX), web services, scripting language support (to integrate JavaScript technology with Java source code using the Rhino scripting engine JSR 223), database connectivity, support for annotations, and security. There are also several new features in the JDBC API ranging from the new RowId support to the additional SQLException subclasses.

JDBC 4.0 Features

Thanks to the Java SE Service Provider mechanism included in Mustang, Java developers no longer need to explicitly load JDBC drivers using code like Class.forName() to register a JDBC driver. The DriverManager class takes care of this by automatically locating a suitable driver when the DriverManager.getConnection() method is called. This feature is backward-compatible, so no changes are needed to the existing JDBC code.

JDBC 4.0 also provides an improved developer experience by minimizing the boiler-plate code we need to write in Java applications that access relational databases. It also provides utility classes to improve the JDBC driver registration and unload mechanisms as well as managing data sources and connection objects.

With JDBC 4.0, Java developers can now specify SQL queries using Annotations, taking the advantage of metadata support available with the release of Java SE 5.0 (Tiger). Annotation-based SQL queries allow us to specify the SQL query string right within the Java code using an Annotation keyword. This way we don't have to look in two different files for JDBC code and the database query it's calling. For example, if you have a method called getActiveLoans() to get a list of the active loans in a loan processing database, you can decorate it with a @Query(sql="SELECT * FROM LoanApplicationDetails WHERE LoanStatus = 'A'") annotation.

Also, the final version of the Java SE 6 development kit (JDK 6)--as opposed to the runtime environment (JRE 6)--will have a database based on Apache Derby bundled with it. This will help developers explore the new JDBC features without having to download, install, and configure a database product separately.

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
  6. SQL XML support

There are also other features such as improved support for large objects (BLOB/CLOB) and National Character Set Support.More>>

Java 6 Platform Revealed -- written by John Zukowski and published by APress

About the Book:
After a quick overview of some of the new features in the Java SE 6 platform, Chapter 2 presents some of the language and utility updates. For example, here's an interesting addition: Did you know about the new java.io.Console class? You can get a hold of this using the System.console() method. The canonical example on page 16 shows us one of several differences between using the old System.out method and the new java.io.Console:
System.out.println("Espanol");
System.console().printf("%s%n", "Espanol");

With the method on the first line, println() is used with an PrintStream object, which will throw away the high-order bit of each of the String's characters. That's disastrous if you plan to use internationalized characters, such as the ñ in Spanish, because it will instead display a plus-or-minus character (±). However, System.console().printf() will preserve the proper character data, displaying international characters correctly.

Also, here's some functionality that I'll be using quite a bit: the new Deque interface. That's a double-ended queue, pronounced "deck" instead of the "de-queue" you might expect, which allows you to add and remove items from either end of a queue collection. As expected, you can traverse the queue from either direction, front to back or back to front. The java.util.LinkedList utility class is one that you are most likely to use that implements the Deque interface.

Chapter 4 lists plenty of additions to the platform in the Abstract Window Toolkit (AWT) and Java Foundation Classes/Swing (JFC/Swing) arena. Articles published on java.sun.com have discussed most of these topics, but Zukowski's book reviews them in great detail. These additions include the following:

  • Splash screens
  • System tray
  • New dialog modality model
  • Text antialiasing
  • Table sorting and filtering
  • Inclusion of SwingWorker in the JFC/Swing libraries

The last item is one of my favorite additions. Since the 1998 publication of the SwingWorker class in the article "Threads and Swing," developers have repeatedly requested that Sun move it into the Core Java technologies. At the 2004 JavaOne conference, the Java Desktop team presented a new version of SwingWorker that included generification, use of the concurrency package, and PropertyChangeListener support. Much of this functionality assists with interthread communication. The Java SE 6 platform incorporates a similar version of SwingWorker that greatly assists developers in processing GUI-driven functionality off the event-dispatching thread, indicating status and progress, and aggregating the results.

If you work with Java Platform, Enterprise Edition (Java EE), then you definitely want to keep Chapter 5 handy. This chapter covers Java Database Connectivity (JDBC) 4.0 in exquisite detail. Writers have also discussed this topic in articles on java.sun.com, but following is a list of the most common changes in the java.sql and javax.sql packages:

  • Database driver loading
  • Exception-handling improvements
  • Enhanced Binary Large Object (BLOB)/Character Large Object (CLOB) functionality
  • Connection and statement interface enhancements
  • Locale-specific character set support
  • SQL ROWID access
  • SQL 2003 XML data type support
  • Annotations
Chapter 6 introduces some of the new XML libraries, including the Java Architecture for XML Binding (JAXB) libraries now located at javax.xml.bind, the XML digital signature libraries at javax.xml.crypto, and the libraries for the Streaming API for XML (StAX) at javax.xml.streamjavax.xml.transform.stax, among others. Zukowski discusses a myriad of changes in this chapter, so read it carefully and augment it with the official documentation if you plan to parse and output XML in your Java platform application.
Chapter 7 introduces the new features of web services in the Java SE 6 platform. Probably the most important is that you can now use annotations in front of your classes and methods to indicate that they are intended for web services. Here's an example:

@WebService
public class HelloService{
@WebMethod
public String HelloWorld(){
return "Hello, World";
}
}
One caution: Zukowski's book does not mention that the Java SE 6 platform can now act as a web-service server, as this article shows in more detail. This is likely because the feature was not yet available when his book went to press.

Finally, did you know that you can now run JavaScript technology inside the Java SE 6 platform? Zukowski discusses this in Chapter 9, which goes over the classes in the javax.script package.
This package contains only a few classes and interfaces, but it won't take you long to figure out how to invoke the embedded Rhino JavaScript interpreter using the ScriptEngine.eval() method, as well as binding your own Java objects to objects inside the JavaScript technology interpreter.More>>

0 Comments:

Post a Comment

<< Home