Java 7 – New features
Everything you wanted to know about Java
7




 http://arraylist.blogspot.com
Java 7 – New features
String data type in the switch block for the switch-case statement.
public void getArea(FloorPlan fp) {
        String shape = fp.getShape();

       switch (shape) {

       case SQUARE:
          calculateArea(fp.getLength());
          break;

       case RECTANGLE:
          calculateArea(fp.getLength() * fp.getBreadth());
          break;

       default:
          break;
       }
   }




http://arraylist.blogspot.com
Java 7 – New features
Enhanced catch block in the try-catch
statement. A single catch block to catch multiple
exception - where the exceptions are separated
by pipes.

try {
   someMethod();
  }
catch (ExceptionA | ExceptionB | ExceptionC e)
{
   // handle exceptions
  }

http://arraylist.blogspot.com
Java 7 – New features
Collections api introduces - A lightweight
fork/join framework.

More classes –
Phaser - a resuable and flexible
synchronization barrier
ThreadLocalRandom – generates a random
number dedicated to the present thread.

Interfaces - ConcurrentLinkedDeque
,TransferQueue .


http://arraylist.blogspot.com
Java 7 – New features
Improved Diamond(<>) operator in generics where the
data type inside the <> generic operator of the left hand
side is automatically inferred to the right hand side to
improve readability and reduce code clutter.
for example :-

//previously
List<Integer, List<String>> list = new ArrayList<Integer,
List<String>>();

//in jdk7
List<Integer, List<String>> list = new ArrayList<>();




http://arraylist.blogspot.com
Java 7 – New features
Numerical literals
Long numbers are easier to read and neatly
identified using numerical literals
Now 1 million can be declared in a more
readable way.
Old
 int onemillion = 1000000;

New
int onemillion = 1_000_000;



http://arraylist.blogspot.com
Java 7 – New features

The enhanced try statement as
try-with-resource

try(FileInputStream fis = new
FileInputStream("somefile.txt")){
        //do something
}




http://arraylist.blogspot.com
Java 7 – New features


    For more interesting stuff visit

      http://arraylist.blogspot.com




http://arraylist.blogspot.com

New features in Java 7

  • 1.
    Java 7 –New features Everything you wanted to know about Java 7 http://arraylist.blogspot.com
  • 2.
    Java 7 –New features String data type in the switch block for the switch-case statement. public void getArea(FloorPlan fp) { String shape = fp.getShape(); switch (shape) { case SQUARE: calculateArea(fp.getLength()); break; case RECTANGLE: calculateArea(fp.getLength() * fp.getBreadth()); break; default: break; } } http://arraylist.blogspot.com
  • 3.
    Java 7 –New features Enhanced catch block in the try-catch statement. A single catch block to catch multiple exception - where the exceptions are separated by pipes. try { someMethod(); } catch (ExceptionA | ExceptionB | ExceptionC e) { // handle exceptions } http://arraylist.blogspot.com
  • 4.
    Java 7 –New features Collections api introduces - A lightweight fork/join framework. More classes – Phaser - a resuable and flexible synchronization barrier ThreadLocalRandom – generates a random number dedicated to the present thread. Interfaces - ConcurrentLinkedDeque ,TransferQueue . http://arraylist.blogspot.com
  • 5.
    Java 7 –New features Improved Diamond(<>) operator in generics where the data type inside the <> generic operator of the left hand side is automatically inferred to the right hand side to improve readability and reduce code clutter. for example :- //previously List<Integer, List<String>> list = new ArrayList<Integer, List<String>>(); //in jdk7 List<Integer, List<String>> list = new ArrayList<>(); http://arraylist.blogspot.com
  • 6.
    Java 7 –New features Numerical literals Long numbers are easier to read and neatly identified using numerical literals Now 1 million can be declared in a more readable way. Old int onemillion = 1000000; New int onemillion = 1_000_000; http://arraylist.blogspot.com
  • 7.
    Java 7 –New features The enhanced try statement as try-with-resource try(FileInputStream fis = new FileInputStream("somefile.txt")){ //do something } http://arraylist.blogspot.com
  • 8.
    Java 7 –New features For more interesting stuff visit http://arraylist.blogspot.com http://arraylist.blogspot.com