Top 5 Features in Java 7

One of the core principles of Agile Programming, is to keep the Code DRY.  DO NOT REPEAT YOURSELF, KEEP THE CODE DRY.
Below features of Java7 demonstrates it
1. Type Inference For Generic Instance Creation
* Agile DRY Feature
Map<String, List<String>) myMap = new HashMap;
Finally, We going to save some typing efforts and Eclipse Warnings.
2. Better way to handle Multiple Exceptions
* Agile DRY feature
try {
//your code
}catch(IOException, SQLException, Exception ex){
logger.log(ex);
throw ex;
}
3. Switch Statement now Supports Strings
I used to miss this sometimes, so if you had to use switch, you could either map it to a number
String weekday =”sunday”;
Switch(weekday){
case “Monday” :    log.debug(“Monday”);
break;
}
4. Elvis Operator
Part A
//Lets say you recieve a String from a method
String s = getFirstName();
//Before you could use it you will, have to make sure its not NULL to avoid Null Pointer Exception. Elvis Operator fixes the issue
String s = getFirstName()?.toString()?:”null”; // See how a Oneliner is doing the code
Part B
Integer iVal = getEmpId(); //may be null
int empId = iVal?:-1 ; //Assign -1 if the value is null

5. NIO2  FileSystem API
- More efficient support to copy and move files
- Cloud File Systems
- Enhanced Exceptions e.g file.delete() now throws an Exception Instead of IOException

Originally published on Careerinjava.com on Aug 2013

Comments

Popular posts from this blog

Apache Airflow Wait Between Tasks

Hibernate Interview Questions

Java Spring Interview Questions