Features and Enhancement in jdk1.7

Given below are the areas in which new features are added and enhancement is done:

  • Swing
  • IO and New IO
  • Networking
  • Security
  • Concurrency Utilities
  • Rich Internet Applications (RIA)/Deployment
  • Java 2D
  • Java XML - JAXP, JAXB, and JAX-WS
  • Internationalization
  • java.lang Package
  • Java Programming Language
  • Java Virtual Machine (JVM)
  • JDBC
  • Java Language Features
  • Binary Literals
  • Underscore in Numeric literals
  • String in Switch statements
  • The try with resources statement
  • Catching multiple exceptions by single Catch

Binary literals is a new addition introduced in Java 7, wherein we can express the integral types (byte,short,int & long) by using Binary number System. To specify a binary literal, add the prefix 0b or 0B to the number.

The following example shows how binary literals work :

From the time Java 7 was introduced we can write any number of underscore characters like ( _ ) and which can appear anywhere between the digits. This feature enables you to separate groups of digits in numeric literals,which can improve the readability of your code.

It must be kept in mind though, that underscores will be omitted in operations.
Example:

Before jdk 7, only numbers were allowed in switch Case statement. But now, in jdk 7, we can use string object in switch case Statements.
Switch case strings should be enclosed in "double quotes."

Example:

Question : How to deal with resource management and how has it changed with Java 7?

Managing resources that needed to be explicitly closed was somewhat tedious before Java 7. Any object that implements java.lang.AutoCloseable, can be used as a resource. So, to have the best resource management, you need to:

  • You have to write finally block to make sure that all the resources are freed before closing of the program before this concept was introduced.

  • Try with resources that will make sure that the resource will be freed no matter whether try completes abruptly or successfully.

  • Try must have catch or must have throws clause to use this concept.


Consider the following Example:

  • Before this concept introduced for handling more than one exception we need to write mutiple catch statements.

  • Now, in Jdk 7, we can write multiple catch exceptions in single catch statement.


Example: A single catch block can handle more than one type of exception