JDK 1.7 Features Java 7

The latest version of Java, as on today (September 1, 2013) is Java 7 released on July 28, 2011 by Oracle Corporation.

The latest update to Java 7 is 25 and was released on June 18, 2013.

Always two ideas basically remain in Java designers’ minds while designing the language; while adding new features to every new Java version released.

  1. How to make the language simple to use by the developer, by decreasing the coding part?
  2. How to increase the performance?
JDK 1.7 Features

Following is the list of new features added, of daily importance.

1. String in Switch Expression
2. Underscores Between Digits in Numeric Literals
3. Integral Types as Binary Literals
4. Handling multiple exceptions in a single catch block
5. Try-with-resources Statement
6. Automatic Type Inference in Generic object instantiation

Only feature (the first one) is shown here as it is very interesting for every one even for C/C++ Programmers.

Generally switch takes a parameter of int data type or convertible to int (remember does not take long data type). But, one of JDK 1.7 Features is switch accepts string as parameter.

Following is the example on switch with parameter string (of JDK 1.7 Features)
public class SwitchStrings
{
  public static void main(String args[])
  {
    StringBuffer  sb = new StringBuffer();
  
    for(String str : args)
    {
      switch(str)
      {
        case "Idly":	sb.append(str +", ");   break;
        case "Dosa":	sb.append(str +", ");   break;
        case "Puri":	sb.append(str +", ");   break;
        case "Vada":	sb.append(str);         break;
        default:        sb.append("No breakfast menu");
      }
    }
    System.out.println("Your breakfast menu: " + sb);
  }
}

JDK 1.7 Features Switch does case-sensitive comparison with case statements. Switch gives a more efficient and cleaner code than if-else if-else code.

All the above features with full example programs are discussed elaborately at length in JDK 1.7 Features.

Leave a Comment

Your email address will not be published.