What is Java 7---High level goal?
The release of the Java version of almost all platforms involves all aspects of the Java language itself and the JVM. So for Java 7, from the JSR draft, we get the high-level goal of Java 7:
Compatibility-Any program running on previous versions must be able to run in Java SE 7 without making any changes;
Development efficiency-improve the development efficiency, the smallest learning curve;
Performance-a new parallel API interface that introduces a true asynchronous I/O API that makes I/O-intensive applications have better performance;
Applicability-the ability to speed up the performance of other dynamic languages on Java virtual machines;
The ―java SE 7 will include a new, flexible file system API as part of the JSR203.
Basic new features of Java 7
Enhancements to the Java language features (JSR334)
Project Coin mainly makes some minor improvements to the Java language to improve the productivity of Java developers:
String type allowed in Switch statement
Listing 1. String type examples are allowed in Switch statements
Switch (myString) {case
' one ': <do something>; break;
Case "Two": <do something else>; break;
Default: <do something generic>;
}
Provides type inference for creation of common type instances
Listing 2. Provides type inference examples for creation of common type instances
map<string,mytype> foo = new map<string,mytype> ();
becomes:
Map <String,MyType> foo = new map<> ();
}
Multi Catch to handle a variety of exception types
Listing 3. Multi Catch to handle a variety of exception types examples
Java 6:
Try {
...
} catch (Exception a) {
handle (a);
} catch (Error b) {
handle (b);
}
Java 7:
Try {
...
} catch (Exception | Error a) {
handle (a);
}
Binary constants and numeric constants examples
0b10011010 34_409_066
Automatic resource management mechanism
In the Java program, handling all possible failure paths is difficult, and closing resources is also relatively difficult, so in the Java 7 implementation, resource management obtains the help of compilers, by defining a resource interface that allows the compiler to automatically shut down resources when appropriate, freeing up resources such as memory.
Automatic Resource Management Example
Try (inputstream inFile = new FileInputStream
(afilename);
OutputStream outfile = new FileOutputStream (afilename)) {
byte[] buf = new Byte[buf_size];
int readbytes;
while ((Readbytes = Infile.read (buf)) >= 0)
infile.write (buf, readbytes);