Home United States USA — software SKP's Java/JEE Gotchas: Revisiting Java SE 7 Features! SKP's Java/JEE Gotchas: Revisiting...

SKP's Java/JEE Gotchas: Revisiting Java SE 7 Features! SKP's Java/JEE Gotchas: Revisiting Java SE 7 Features!

322
0
SHARE

In prep for Java 9, let’s examine how Java 7 brought us Strings in switch statements, automatic resource management in try statements, and the diamond operator.
Preparing for an interview? Want to just revisit Java SE 7 features? Trying to recollect or revise a Java SE programming construct? Let me take you back in time to what was introduced first in Java SE 7? Join me for this tutorial series on Java as we all eagerly await the official release of Java SE 9!
Strings in switch statements.
Automatic resource management in try statements.
Improved type inference for generic instance creation, AKA the diamond operator <>.
Simplified varargs method declaration.
Binary integer literals.
Allowing underscores in numeric literals.
Catching multiple exception types and rethrowing exceptions with improved type checking.
I have provided some of the most important core language enhancements for JDK 7.0, along with code samples. The examples provided below can be directly pasted into your IDE, and you may name the class as provided.
Before JDK7, you would have to catch multiple exceptions in a block — with a catch block for each of the thrown checked exceptions. But sometimes you may want to take actions for many exceptions that are similar or the same. Hence, the utility of this feature. You may directly execute the code below in Eclipse to understand it better.
Sometimes when we are using generics in an application, we may end up with a long line of code, which may be very confusing or have poor readability. This is because there may be multiple generic types that are used in the same line. To improve upon this, JDK7 introduces the concept of the diamond operator or diamond syntax, where the type of the generic variable is inferred.
Java SE 5
Java SE 6

Continue reading...