A nice Java 7 feature is the new try-with-resources statement.
When you did some SQL things back in the Java 6 days, you often ended up with something like this:
12345678910111213141516171819
try{Connectioncon=createConnection();// do somethingStatementstmt=null;try{stmt=con.createStatement();ResultSetrs=stmt.executeQuery("SELECT ...");// do something with rsrs.close();}catch(SQLExceptione){e.printStackTrace();}finally{if(stmt!=null){stmt.close();}}}finally{con.close();}
Now with Java 7, this got a lot easier and shorter:
123456789
try(Connectioncon=createConnection()){// do somethingtry(Statementstmt=con.createStatement();ResultSetrs=stmt.executeQuery("SELECT ...")){// do something with rs}catch(SQLExceptione){e.printStackTrace();}}
Awesome!
If you want to write a class that supports this syntax, you may take a look a the AutoClosable interface.