The Java 7 Features Bound to Make Developers More Productive

If you've tracked each major Java release, you probably were eager to see what new packages were in each one and how you could employ them in your Java projects. Along the same lines, the next major Java SE release, Java 7, promises several new features across all packages, such as modularization, multi-language support, developer productivity tools, and performance improvement. I think programmers eventually will begin specializing in individual Java packages (i.e., java.util programmers, java.io programmers, java.lang programmers, etc.), but until then, let's explore a few of the notable new developer productivity features slated for Java 7.

Find examples of all the features discussed here in the code download for this article.

New Objects Class

The new Objects class of the java.util package provides a fail-proof way for comparing two objects at runtime:

The equals() method of the Objects class does a reference comparison. The deepEquals() method piggybacks on the first argument's equals() method definition.

Similarly, when both the arguments are object arrays, Array.deepEquals() is invoked on the objects. The new Objects class provides all the required static utility methods.

New Classes to Operate on File System

Java SE 7 provides classes that greatly simplify the age old integration processes of one application dropping files at a predefined shared location and other application picking them up. Java 7 provides a new class WatchService that notifies any events that take place in the file system under the watch.

The following steps create an asynchronous file-watcher service:

Obtain the path from the File class. Path fPath = new File(filePath).toPath();



Obtain a handle to the Watch service from the file system. dirWatcher = fPath.getFileSystem().newWatchService();



Register which type of events you are interested in. Related Articles Non-Blocking I/O Made Possible in Java

Keynote highlights from JavaOne 2005 fPath.register(dirWatcher, StandardWatchEventKind.ENTRY_CREATE, StandardWatchEventKind.ENTRY_DELETE, StandardWatchEventKind.ENTRY_MODIFY);



Wait for the event to happen. try{ WatchKey key = dirWatcher.take(); }catch(InterruptedException ie){ return; }



The WatchKey class now has all the details of the event that occurred in the directory.



Loop through Step 4 to continue receiving events.

New Classes for Concurrency Package

The Java SE team added a wide variety of new classes to Java 7 to cater to various concurrency functionalities. Most notable among them are the RecursiveAction and RecursiveTask classes, which simplify new algorithm development. Understanding the difference between heavyweight and lightweight processes will help you grasp the value of these new classes.

A heavyweight process gets a replica of the code, stack, and data from the parent process. You create a heavyweight process by invoking fork() .

. A lightweight process gets its own stack and shares resources and data with other threads or the parent thread. The Unix Thread API standard (POSIX) provides methods to create a thread.

Java 7 defines a new abstract class called ForkJoinTask, a lightweight process that generates a distinct stream of control flow from within a process. RecursiveAction and RecursiveTask are abstract subclasses of ForkJoinTask.

To code a recursive call, you must subclass either one of these classes and define the compute() method. The getRawResult() method returns null for RecursiveAction and returns a value for RecursiveTask. The Java 7 documentation provides a simple example for each of these classes.

Code Development Made Too Easy?

For me, the joy of being a computer scientist is spending long hours writing code for various algorithms. The problem solving keeps my mind alert, and the computations keep going in my head even in sleep. All the utilities in Java 7 take much of that joy of programming away, but they contribute to the bottom line for the companies supporting Java projects, which is what really matters for Java.

Code Download

Java7code For Further Reading