Friday, 23 December 2011


Java SE 6 incorporates a broad range of
enhancements to the infrastructure of Java rather
than specific syntax enhancements
(unlike Java 5)
• Java SE 6 features include:
– XML and Web services support
– JDBC 4.0 support
– More Annotation types
– More flexible annotation processing
– Jave compiler APIs accessible from programs
– Application client GUI enhancements for both
AWT and Swing


XML & Web Services Support
• Javas SE 6 address the growth of Web services
and XML processing in the Java community
including support for:
– Web Services client stack
– Streaming API for XML (StAX)
– Java Architecture for XML Binding (JAXB) 2.0
– Java API for XML-based Web services (JAXWS) 2.0 Web services metadata
– XML digital signature APIFebruary 2010 Copyright @ 2010, John Jay King
Page 61
New JDBC 4.0 Features
• Java SE 6 includes JDBC 4.0; designed to
improve ease of JDBC development by:
– Simplified access to relational data sources
with utility classes
– Use of generics and annotations
– Addition of JDBC 4.0 wrapper pattern
– Safe access to vendor-specific APIs
– Automatic driver discovery
– Enhanced connection management
– New data types
(including XML and SQL ROWID)February 2010 Copyright @ 2010, John Jay King
Page 62
Annotation-based Development
• Annotations were in Java 5.0 allowing developers
to embed metadata in Java source code
• Java SE 6 includes additional built-in annotation
types and annotation-processing APIs including:
– Web services metadata for the Java Platform
(JSR 181)
– Common Annotations for the Java Platform
(JSR 250)
– Pluggable Annotation Processing API
(JSR 269)February 2010 Copyright @ 2010, John Jay King
Page 63
Java Compiler APIs
• Java command-line compilers receive input from
the file system and report errors using a stream
• Java SE 6 allows the compiler to receive input
and/or send output to an abstraction of the file
system
• Java programs may now specify compiler
directives and process compiler output (this
feature was add mostly due to software vendor
requests)February 2010 Copyright @ 2010, John Jay King
Page 64
Application GUI Client APIs
• Java SE 6 enhances application GUI capabilities
with changes to both AWT and Swing
• AWT
– Faster splash screens (using native code)
– System tray support (icons & messages)
– Access to browsers and other desktop
application “helpers”
• Swing
– Improved drag-and-drop support
– Enhanced layout customization
– Simplified multi-thread programming
– Writing of GIF imagesFebruary 2010 Copyright @ 2010, John Jay King
Page 65
Other Java SE 6 Features
• Changes to Java class file specification
(JSR 202)
• Framework to connect Java programs to
scripting-language interpreters (JSR 223)
• New bi-directional (allowing backward navigation)

Java 1.7 Features



Oracle’s Java 1.7 is currently in progress. Java 1.7 / Java SE 7 are expected to contain many enhancements and new features when compared to Java 1.6 and Java 1.5. An overview on enhancements of Java 1.7 is:
JDBC in Java 1.7
JDBC contained in Java 1.7 / Java SE 7 is JDBC 4.1 that is newly getting introduced. JDBC 4.1 is more efficient when compared to JDBC 4.0.
Language Enhancements in JDBC 1.7
Java 1.7 introduces many language enhancements:
Integral Types as Binary Literals – In Java 1.7 / Java SE 7, the integral types namely byte, short, int and long can also be expressed with the binary number system. To specify these integral types as binary literals, add the prefix 0B or 0b to number. For example, here is a byte literal represented as 8-bit binary number:
 
byte sampleByte = (byte)0b01001101;
Underscores Between Digits in Numeric Literal – In Java 1.7 and all later versions, “_” can be used in-between digits in any numeric literal. “_” can be used to group the digits similar to what “,” does when a bigger number is specified. But “_” can be specified only between digits and not in the beginning or end of the number. Example:
 
long SSN = 819_44_9789L;
String Object as Expression in Switch Statement – So far only integral types are used as expressions in switch statement. But Java 1.7 permits usage of String object as a valid expression. Example:
 
public void sampleMethod(String sampleString)
{
            switch (sampleString)
            {
                       case "ONE":
                                    System.out.println(“Entered ONE”);
                                    break;
                    case "TWO":
                                    System.out.println(“Entered TWO”);
                                    break;
                    case "THREE":
                                    System.out.println(“Entered THREE”);
                                    break;
                    default:
                                    System.out.println(“Entered string other than ONE,TWO,
THREE”);
            }
}
In this example, the switch expression contains a string called sampleString.  The value of this string is matched with every case label and when the string content matches with case label then the corresponding case gets executed. 
Automatic Type Inference during the Generic Instance Creation – In Java 1.7 while creating a generic instance, empty parameters namely <> can be specified instead of specifying the exact type arguments. However, this is permitted only in cases where the compiler can infer the appropriate type arguments. For example, in Java 1.7 you can specify:
 
Map> sampleMap = new HashMap<>();
Thus HashMap<> can be specified instead of HashMap>. This <> empty parameters of Java 1.7 are named as diamond operator.
Try Statement defining Resources – Java 1.7 introduces all new try-with-resources statement using which declaration and initialization of one or more resources can happen. But only the resources that implement the interface “java.lang.AutoCloseable” can be declared. Example:
 
      try (BufferedReader sampleBufferedReader = new BufferedReader(
                        FileReader(samplePath)))
      {
             return sampleBufferedReader.readLine();
       }
In this code snippet, sampleBufferedReader instance is created within the try statement. Note that the example does not include a finally block that contains a code to close sampleBufferedReader as in Java 1.6 or earlier versions. Java 1.7 automatically closes the resources that are instantiated within the try-with-resources statement as shown above.
Catch Block Handling Multiple Exceptions – In Java 1.5 and Java 1.6, a catch block can handle only one type of exception. But in Java 1.7 and later versions, a single catch block can handle multiple exceptions. Here is an example showing catch blocks in Java 1.6:
 
     try
      {
         //…
      }
      catch(SQLException exp1)
      {
                throw exp1;
       }
       catch(IOException exp2)
       {
            throw exp2;
       }
       catch(ArrayIndexOutofBoundsException exp3)
       {
              throw exp3;
       }

The same code snippet can be modified in Java 1.7 as:
 
      try
      {
         //…
      }
      catch(SQLException | IOException | ArrayIndexOutofBoundsException exp1)
      {
                throw exp1;
       }

Suppress Warnings - When declaring varargs method that includes parameterized types, if the body of the varargs method does not throw any exceptions like ClassCastException (which occurs due to improper handling of the varargs formal parameter) then the warnings can be suppressed in Java 1.7 by three different ways: (1) Add annotation @SafeVarargs to static method declarations and non constructor method declarations (2) Add annotation @SuppressWarnings({"unchecked", "varargs"}) to varargs method declaration (3) Directly use compiler option “-Xlint:varargs.
By suppressing the warnings in varargs method, occurrence of unchecked warnings can be prevented at compile time thus preventing Heap Pollution.
Java Virtual Machine Enhancements in Java 1.7
Java SE 7 / Java 1.7 newly introduce a JVM instruction called “invokedynamic” instruction.  Using “invokedynamic” instruction, the dynamic types programming language implementation becomes simpler. Thus Java 1.7 enables JVM support for the non-java languages.