Java 7 Changes –
1) String in Switch Case
2) Binary Literals
Before –
public void testBinaryIntegralLiterals(){
int binary = 8;
if (binary == 8){
[Link](true);
} else{
[Link](false);
}
}
Java 7 –
public void testBinaryIntegralLiterals(){
int binary = 0b1000; //2^3 = 8
if (binary == 8){
[Link](true);
} else{
[Link](false);
}
}
3) Underscore Between Literals
4) Diamond Syntax
Before –
public void testDinamond(){
List list = new ArrayList();
Map> map = new HashMap>();
}
Java 7 –
public void testDinamond(){
List list = new ArrayList<>();
Map> map = new HashMap<>();
}
5) Multi-Catch Similar Exceptions
Before –
public void testMultiCatch(){
try {
throw new FileNotFoundException("FileNotFoundException");
} catch (FileNotFoundException fnfo) {
[Link]();
} catch (IOException ioe) {
[Link]();
}
Java 7 –
public void testMultiCatch(){
try {
throw new FileNotFoundException("FileNotFoundException");
} catch (FileNotFoundException | IOException fnfo) {
[Link]();
}
}
6) Try with Resources
Before –
public void testTryWithResourcesStatement() throws FileNotFoundException,
IOException{
FileInputStream in = null;
try {
in = new FileInputStream("[Link]");
[Link]([Link]());
} finally {
if (in != null) {
[Link]();
}
}
}
Java 7 –
public void testTryWithResourcesStatement() throws FileNotFoundException,
IOException{
try (FileInputStream in = new FileInputStream("[Link]")) {
[Link]([Link]());
}
}
7) The [Link] package
a. The [Link] package and its related package, [Link],
provide comprehensive support for file I/O and for accessing the file system. A
zip file system provider is also available in JDK 7.
8)