Collections Framework Enhancements
These new collection interfaces are provided:
- Deque - a double ended queue, supporting element insertion and removal at both ends. Extends the Queue interface.
- BlockingDeque - a Deque with operations that wait for the deque to become non-empty when retrieving an element, and wait for space to become available in the deque when storing an element. Extends both the Deque andBlockingQueue interfaces. (This interface is part of java.util.concurrent.)
- NavigableSet - a SortedSet extended with navigation methods reporting closest matches for given search targets. A NavigableSet may be accessed and traversed in either ascending or descending order. This interface is intended to supersede the SortedSet interface.
- NavigableMap - a SortedMap extended with navigation methods returning the closest matches for given search targets. A NavigableMap may be accessed and traversed in either ascending or descending key order. This interface is intended to supersede the SortedMap interface.
- ConcurrentNavigableMap - a ConcurrentMap that is also a NavigableMap. (This interface is part of java.util.concurrent.)
The following concrete implementation classes have been added:
These existing classes have been retrofitted to implement new interfaces:
- LinkedList - retrofitted to implement the Deque interface.
- TreeSet - retrofitted to implement the NavigableSet interface.
- TreeMap - retrofitted to implement the NavigableMap interface.
The
Arrays utility class now has methods
copyOf and
copyOfRange that can efficiently resize, truncate, or copy subarrays for arrays of all types.
Before:
int[] newArray = new int[newLength];
System.arraycopy(oldArray, 0, newArray, 0, oldArray.length);
After:
int[] newArray = Arrays.copyOf(a, newLength);
The following new methods were added to
File:
- Methods to retrieve disk usage information:
getTotalSpace() returns the size of the partition in bytes
getFreeSpace() returns the number of unallocated bytes in the partition
getUsableSpace() returns the number of bytes available on the partition and includes checks for write permissions and other operating system restrictions
- Methods to set or query file permissions:
Constructors were added to the following class:
The behavior of the following method was modified:
- The
File.isFile() Windows implementation has been modified to always return false for reserved device names such as CON, NUL, AUX, LPT, etc. Previously it returned true, which customers considered a bug because it was inconsistent with behavior for devices on Unix.
JDK 7 vs JDK 6
Utilities :-
- Fork Join Pool :- A
ForkJoinPool differs from other kinds of ExecutorService mainly by virtue of employing work-stealing: all threads in the pool attempt to find and execute subtasks created by other active tasks (eventually blocking waiting for work if none exist). This enables efficient processing when most tasks spawn other subtasks (as do most ForkJoinTasks). When setting asyncMode to true in constructors, ForkJoinPools may also be appropriate for use with event-style tasks that are never joined.
- Phaser :- A reusable synchronization barrier, similar in functionality to
CyclicBarrier and CountDownLatch but supporting more flexible usage.
Java Programming Lang :-
- Strings are allowed in switch statements.
- try with resource :- no need to close resources for FileStream, Socket, Data connection etc all classes that are implementing AutoCloseable interface. try (Statement stmt = con.createStatement()) {} catch {}
- Catching Multiple Exception Types and Rethrowing Exceptions with Improved Type Checking
catch (IOException|SQLException ex) {
logger.log(ex);
throw ex;
}
- Underscores in numeric literals :-
132_465_789
- Type inference for generic type :-
Map aMap = new HashMap<>();
- JVM support for non java language :- Use bootstrap method & use invokedynamic method.
- Garbage First collector :- The G1 collector is a server-style garbage collector, targeted for multi-processor machines with large memories. It meets garbage collection (GC) pause time goals with high probability, while achieving high throughput. Whole-heap operations, such as global marking, are performed concurrently with the application threads. This prevents interruptions proportional to heap or live-data size. G1 is planned as the long term replacement for the Concurrent Mark-Sweep Collector (CMS).
JDK 8 vs JDK 7
Lambda :- Java compiler compiles lambda expression into private method & using invokedynamic bind this method dynamically.
Default methods enable you to add new functionality to the interfaces of your libraries and ensure binary compatibility with code written for older versions of those interfaces. An interface can have multiple default methods.
Interface can have static methods.
Functional Interface :- has only one abstract/normal method, but can have multiple default methods. With Java 8 the same concept of SingleAbstractMethod (SAM) interfaces is recreated and are called Functional interfaces. Some popular SAM interface are java.lang.Runnable, java.awt.event.ActionListener, java.util.Comparator, java.util.concurrent.Callable.
Nashorn :-
Stream class in util :-
No comments:
Post a Comment