Wednesday, July 16, 2014

Java7 Features

We have the following features are there in java7 version they are,

1. In Java 7:

  int allows numbers and underscore.
So, it is easy to read the numbers. Especially when declare amount, in integer it’s easy to read it and avoid confusion.
2 SampleArrayList
Before Java 7:
                                        List<String> al=new ArrayList<String>();
In Java 7:
                              List<String> al=new ArrayList<>();
3) SampleSwitch.java
Before Java 7:
                        String not allowed in switch statement. Switch allows only character and numeric. If we need to compare a string in switch statement, assign string values to an numeric and use it in switch statement.
In Java 7:
                    Java 7 allows String in switch statement. So, we can directly use strings in switch statement.
4) SampleException.java
Before Java 7:
                                        catch(ArithmeticException e){}
                                         catch(NumberFormatException){}
                                         catch(NullPointerException){}
                                        catch(IOException){}
In Java 7: 
               catch(ArithmeticException|NumberFormatException|NullPointerException|IOException e){}
It’s more simple than the previous. Multiple catch can be handled in one catch statement.



No comments:

Post a Comment