0% found this document useful (0 votes)
27 views3 pages

Java 7 Changes - : 1) String in Switch Case 2) Binary Literals

Uploaded by

Ganesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views3 pages

Java 7 Changes - : 1) String in Switch Case 2) Binary Literals

Uploaded by

Ganesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Java 7 Changes –

1) String in Switch Case


2) Binary Literals

Before –

public void testBinaryIntegralLiterals(){


int binary = 8;
if (binary == 8){
System.out.println(true);
} else{
System.out.println(false);
}
}

Java 7 –

public void testBinaryIntegralLiterals(){


int binary = 0b1000; //2^3 = 8
if (binary == 8){
System.out.println(true);
} else{
System.out.println(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) {
fnfo.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
}

Java 7 –

public void testMultiCatch(){


try {
throw new FileNotFoundException("FileNotFoundException");
} catch (FileNotFoundException | IOException fnfo) {
fnfo.printStackTrace();
}
}

6) Try with Resources

Before –

public void testTryWithResourcesStatement() throws FileNotFoundException,


IOException{
FileInputStream in = null;
try {
in = new FileInputStream("java7.txt");
System.out.println(in.read());
} finally {
if (in != null) {
in.close();
}
}
}

Java 7 –

public void testTryWithResourcesStatement() throws FileNotFoundException,


IOException{
try (FileInputStream in = new FileInputStream("java7.txt")) {
System.out.println(in.read());
}
}
7) The java.nio.file package
a. The java.nio.file package and its related package, java.nio.file.attribute,
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)

You might also like