New Changes in JDK7
October 9, 2012 Leave a comment
JDK7 is packaged with these new changes
– Small language changes
– NIO-2 Enhanced NIO
– invokedynamic
– other features
Small language Changes:
- Now integer can accept binary format (along with octal and hexadecimal values)
<pre>int i = 0b10110
- Switch statement can accept string variables. Since String object in Java is considered immutable, java community has come up with this concept
usage:
public int useSwitch(String strCase) {
switch(strCase) {
case "A":
return 1;
case "B":
return 2;
...
default:
return 10;
}
}
- Inferring types with <>: while using generics RHS of stmt can be replaced with just <>
usage:
</pre> List<String> list = new ArrayList<>(); <pre>
Note: No need to explicitly mentioned type on the RHS
- Easy rethrow (replace multiple catch blocks with single catch block)
usage:
try {
// Reflective operations calling Class.forName,
// Class.newInstance, Class.getMethod,
// Method.invoke, etc.
...
} catch(final FileNotFoundException |
SQLException |
ClassNotFoundException) {
log(e);
throw e;
}
// try with resources
try (InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(ds)) {
byte[] buf = new byte[8192];
int n;
while ((n = in.read(buf)) >= 0)
out.write(buf, 0, n);
}
NIO-2 Enhanced NIO
NIO-2 (Enhanced Asynchronous NIO)
invokedynamic
Dynamic linking of method by the JVM is introduced
Other Features:
Fork joins (for recursive functionalities) – Multi process environment
Recent Comments