Hi, I would like to highlight what's coming in Java 7. Java 7 has codename Dolphin. That's the longest release ever. It was eventually split into two parts. And the second part will become Java 8.
Java 6 was release in December 2006. It took 4 years to meet feature complete release. That's where list of features is closed. Last scheduled milestone is in June. By then all bugs should be fixed. And Java 7 should be generally available in late July.
The goal of Project Coin was to determine what set of small language changes should be added to JDK 7. There was an open call for proposals that ran in March 2009. Out of nearly 70 proposal few were chosen. Strings in switch statements described here if time allows.
In Java 7 the integral types can also be expressed using the binary number system. To specify a binary literal, add the prefix 0b or 0B to the number. I already see people using it during interviews :)
In Java 7 any number of underscore characters (_) can appear anywhere between digits in a numerical literal. This feature enables you, for example, to separate groups of digits in numeric literals, which can improve the readability of your code. Think of a credit card or telephone number.
In Java 7 you can replace the type arguments required to invoke the constructor of a generic class with an empty set of type parameters (<>). However this will only be possible if compiler can infer the type arguments from the context. This pair of angle brackets is informally called the diamond operator. It will certainly reduce the noise in the Java code.
In Java 7 and later, a single catch block can handle more than one type of exception. This feature can reduce code duplication and lessen the temptation to catch an overly broad exception.
The try-with-resources statement is a try statement that declares one or more resources. And a resource is as an object that must be closed after the program is finished with it. The try-with-resources statement ensures that each resource is closed at the end of the statement. Any object that implements new AutoCloseable interface can be used as a resource. There are 50 interfaces extending AutoCloseable interface - important ones are Connection , ResultSet and Statement (as part of JDBC 4.1) There are over 100 classes implementing AutoCloseable interface - all kind of Streams
In Java 7 we will know not only about files and directories but also about symbolic links, file attributes, permissions, owner, etc. The Path is a main class and has methods for manipulating a path in the filesystem. The FileSystem class has a variety of methods for obtaining information about the file system. Java 7 brings a fully-functional filesystem provider for zip and jar archives, which you will be able to treat as files system. A Path also defines the resolve and resolveSibling methods to combine paths. The relativize method that can be used to construct a relative path between two paths. Paths can be compared, and tested against each other using the startsWith and endWith methods.
The Files class has methods for file operations, such as move, copy, delete, and also methods for retrieving and setting file attributes. This class offers also a rich set of static methods for reading, writing, and manipulating files and directories. Several Files methods, such as move, can perform certain operations atomically in some file systems. An atomic file operation is an operation that cannot be interrupted or &quot;partially&quot; performed.
A WatchService was introduced that watches registered objects for changes and events. You may use a watch service to monitor a directory for changes to be able to update UI when files are created or deleted. The main goal here was to help with performance issues in applications that previously were forced to poll the file system.
Bit of a background. There are two parts of Java really: Java, the language and Java Virtual Machine, so called JVM. Java code is translate or compiled into bytecode that is executed on JVM. There are lots of other languages that can be compiled to bytecode (like Ruby in form of a JRuby). However due to nature of dynamic languages people needed to use workaround or hacks to generate a bytecode and this resulted in worse performance.
In JDK 7, dynamically typed languages should run faster in the JVM than they do today. A key part of support for this is the addition of a new Java bytecode instruction invokedynamic , for method invocation, and an accompanying linkage mechanism that involves a new construct called a method handle.
In summary, method handles provide the linkage mechanism that enables the JVM to invoke the correct method in response to an invokedynamic bytecode instruction. When the JVM sees an invokedynamic bytecode, it uses method handles to get to the method it needs. In a way it could be used for things Java Reflection API was used so far. However, compared to using the Reflection API, access checking is performed when the method handle is created as opposed to every time the method is called, thus is faster.
Although JSR-292 was intended to help dynamically typed languages it will bring huge benefits in other areas. There is a Oracle employee blogging on these other goodies. One of them is that code coverage tools will get faster. Record a visit in a bootstrap method and use method handle to no-op method. Java Specfication Request (JSR)
There are few concurrency updates in Java 7. New is the fork/join framework that helps you take advantage of multiple processors. It is designed for work that can be broken into smaller pieces recursively. This is a style of parallel programming in which problems are solved by splitting them into subtasks that are solved in parallel, waiting for them to complete, and then composing results. Fork/Join framework was intended to be included in the JDK 5, but finally did not make it.
As always there are numerous additions to JAVA API. They are mostly related to changes mentioned earlier, but there are also some utility methods added that might be useful, like Objects class. j ava.util.Objects boolean equals(Object a, Object b) boolean deepEquals(Object a, Object b) int hashCode(Object o) int hash(Object... values) String toString(Object o) String toString(Object o, String nullDefault) <T> int compare(T a, T b, Comparator<? super T> c) <T> T requireNonNull(T obj) <T> T requireNonNull(T obj, String message)
Java 7 adds a close() method to URLClassLoader. This is a methods that frees the underlying resources, such as open files, held by a URLClassLoader. It is a particular problem on Windows, because open files cannot be deleted or replaced.
Leftover from JAVA 7 Lambda expressions are anonymous functions A lot of current API requiring interface with only one method will be much easier to use. The other bit, Project Jigsaw, aims to modularize JDK, split it into smaller parts, provide profiles and download what's necessary as you go.