Dustin's Pages

Thursday, March 31, 2011

JDK 7: New Interfaces, Classes, Enums, and Methods

There are numerous new classes, enums, methods, and interfaces being added to JDK 7 that may not get significant coverage in the blogs and articles on Java 7. In this post, I list and describe some of these. Note that several of these are not really "miscellaneous," but were necessary additions to make greater new functionality available.

There are numerous new concurrency support constructs coming to JDK 7 above and beyond some I highlighted above.

The Locale class documentation mentions "1.7" sixteen times! The 1.7 changes to the class are called out in the class's main description. One significant method is toLanguageTag() that provides "a well-formed IETF BCP 47 language tag representing this locale." The static method forLanguageTag(String) provides an instance of Locale corresponding to the provided String representing the "specified IETF BCP 47 language tag." The very extensive documentation for this method points out an important caveat: "there is no guarantee that toLanguageTag and forLanguageTag will round-trip." The Java Tutorials' Creating a Locale is already updated to reflect using Java 7 features of this class. Among other things, it highlights the new nested Locale.Builder class and the new nested Locale.Category enum.

All of the above are representative of changes coming to the Java SDK with Java SE 7. However, there are numerous additional changes. The Javadoc seems to have been updated fairly well to indicate "Since: 1.7" for features new to JDK 7. One way to "search" for new Java 7 features would be to download the source code and search it for "1.7." Another approach would be to search the generated Javadoc for the same string.

The following Groovy script provides a brute force mechanism for searching the online JDK 7 Javadoc API documentation for methods, classes, enums, methods, and interfaces that contain the string "1.7." I threw this together quickly and believe there are several more elegant ways to do this, but this was easy to write and does the job.

The above Groovy script searches the Javadoc documentation for "1.7" and provides a list of Javadoc files for classes, enums, interfaces, and methods that include the "1.7" string. According to the script's output, 4020 files were searched and 304 of those files contained at least once occurrence of the "1.7" string.

The following Javadoc HTML files were identified by the script as containing the string "1.7" somewhere within the page's documentation. With the exception of a few possible cases in which "1.7" is used for something else, it can be assumed that these are classes, interfaces, and enums that have been marked "Since 1.7."

Not everything new to JDK 7 is properly labeled with "1.7" in its Javadoc documentation (many new constructs in java.lang.dyn do not have "1.7" in their documentation, for example). However, the list above is probably fairly close to the set of files with changes significant enough to be identified in the documentation.

Conclusion

The changes to JDK 7 APIs range from specific (reflection, concurrency, client, JMX) to general (new Objects class) and range in degree to which they will impact the typical Java developer. The list above helps provide an idea of what types of changes an individual Java developer might look forward to with JDK 7.

Thanks for taking the time to improve the script and to leave a comment letting others and me know about it. While I knew my original approach was "brute force" and had some ideas for improvements in mind, the idea of using gpars never occurred to me and is an excellent idea. It seems like a great use to show off the power of parallel processing with gpars.

One of the ideas I was thinking about, but didn't do, was using TagSoup to parse the files and I'm glad your example demonstrates that. I also like your demonstration of Grape's @Grab.