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

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

Java 7 introduced several key changes including the ability to use strings in switch cases and binary literals with the prefix '0b'. It also enhanced syntax with features like underscores in literals, diamond syntax for generics, multi-catch for exceptions, and try-with-resources for automatic resource management. Additionally, the new java.nio.file package provides improved support for file I/O and file system access.

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)
36 views3 pages

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

Java 7 introduced several key changes including the ability to use strings in switch cases and binary literals with the prefix '0b'. It also enhanced syntax with features like underscores in literals, diamond syntax for generics, multi-catch for exceptions, and try-with-resources for automatic resource management. Additionally, the new java.nio.file package provides improved support for file I/O and file system access.

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

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)

You might also like