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.


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.

#!/usr/bin/env groovy
// searchJdk7ApiDocsForSince17.groovy

def anchorString = '<a href="'
def anchorStringUpper = anchorString.toUpperCase()
def urls = new ArrayList<String>()
"http://download.oracle.com/javase/7/docs/api/allclasses-frame.html".toURL().eachLine
{
   def startIndex = -1
   if (it.contains(anchorString))
   {
      startIndex = it.indexOf(anchorString) + anchorString.size()
   }
   else if (it.contains(anchorStringUpper))
   {
      startIndex = it.indexOf(anchorStringUpper) + anchorStringUpper.size()
   }

   if (startIndex > -1)
   {
      def endIndex = it.indexOf('"', startIndex)
      if (endIndex > startIndex)
      {
         def url = it.substring(startIndex, endIndex)
         urls.add(url)
      }
   }
}

def numUrlsProcessed = 0
def numUrlsMatching = 0
println "${urls.size()} total URLs to search for 1.7 text."
def withJava7 = new ArrayList<String>()
urls.each
{
   def match = false
   numUrlsProcessed++
   def eachUrl = "http://download.oracle.com/javase/7/docs/api/${it}"
   try
   {
      if (eachUrl.toURL().text.contains("1.7"))
      {
         numUrlsMatching++
         match = true
         withJava7.add(it)
      }
   }
   catch (Exception ex) // catch HTTP problems like 404 or 504.
   {
      println "ERROR trying to acces ${eachUrl}: ${ex.toString()}"
   }
   println "${numUrlsMatching} of ${numUrlsProcessed} match 1.7 (${match ? eachUrl : '-'})!"
}

println "Javadoc files with 1.7: "
withJava7.each
{
   println "\t${it}"
}

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."

javax/lang/model/util/AbstractAnnotationValueVisitor7.html
javax/lang/model/util/AbstractElementVisitor7.html
java/util/concurrent/locks/AbstractQueuedLongSynchronizer.html
java/util/concurrent/locks/AbstractQueuedSynchronizer.html
javax/lang/model/util/AbstractTypeVisitor6.html
javax/lang/model/util/AbstractTypeVisitor7.html
java/nio/channels/AcceptPendingException.html
java/nio/file/AccessDeniedException.html
java/nio/file/AccessMode.html
java/nio/file/attribute/AclEntry.html
java/nio/file/attribute/AclEntry.Builder.html
java/nio/file/attribute/AclEntryFlag.html
java/nio/file/attribute/AclEntryPermission.html
java/nio/file/attribute/AclEntryType.html
java/nio/file/attribute/AclFileAttributeView.html
java/security/AlgorithmConstraints.html
java/nio/channels/AlreadyBoundException.html
java/applet/Applet.html
java/lang/AssertionError.html
java/nio/channels/AsynchronousByteChannel.html
java/nio/channels/AsynchronousChannel.html
java/nio/channels/AsynchronousChannelGroup.html
java/nio/channels/spi/AsynchronousChannelProvider.html
java/nio/channels/AsynchronousFileChannel.html
java/nio/channels/AsynchronousServerSocketChannel.html
java/nio/channels/AsynchronousSocketChannel.html
java/nio/file/AtomicMoveNotSupportedException.html
java/nio/file/attribute/AttributeView.html
javax/sound/sampled/AudioFormat.Encoding.html
java/lang/AutoCloseable.html
javax/swing/plaf/basic/BasicColorChooserUI.html
javax/swing/plaf/basic/BasicComboBoxUI.html
java/nio/file/attribute/BasicFileAttributes.html
java/nio/file/attribute/BasicFileAttributeView.html
javax/swing/plaf/basic/BasicFileChooserUI.html
javax/swing/plaf/basic/BasicMenuItemUI.html
javax/swing/plaf/basic/BasicScrollBarUI.html
javax/swing/plaf/basic/BasicTreeUI.html
java/util/BitSet.html
java/lang/Boolean.html
javax/swing/BorderFactory.html
java/nio/BufferPoolMXBean.html
java/lang/Byte.html
java/util/Calendar.html
java/sql/CallableStatement.html
java/security/cert/CertificateRevokedException.html
java/security/cert/CertPathValidatorException.html
java/security/cert/CertPathValidatorException.BasicReason.html
java/security/cert/CertPathValidatorException.Reason.html
java/nio/channels/Channels.html
java/lang/Character.html
java/lang/Character.UnicodeBlock.html
java/lang/Character.UnicodeScript.html
java/lang/ClassLoader.html
java/nio/file/ClosedDirectoryStreamException.html
java/util/Collections.html
javax/sql/CommonDataSource.html
java/nio/channels/CompletionHandler.html
java/util/concurrent/ConcurrentLinkedDeque.html
java/util/ConcurrentModificationException.html
java/sql/Connection.html
java/awt/Container.html
java/nio/file/CopyOption.html
java/security/cert/CRLReason.html
java/security/CryptoPrimitive.html
java/util/Currency.html
java/util/spi/CurrencyNameProvider.html
java/awt/Cursor.html
java/sql/DatabaseMetaData.html
java/nio/channels/DatagramChannel.html
javax/swing/text/DefaultStyledDocument.html
javax/swing/tree/DefaultTreeCellRenderer.html
javax/swing/tree/DefaultTreeSelectionModel.html
java/util/zip/Deflater.html
java/util/zip/DeflaterOutputStream.html
javax/print/attribute/standard/DialogTypeSelection.html
java/nio/file/DirectoryIteratorException.html
java/nio/file/DirectoryNotEmptyException.html
java/nio/file/DirectoryStream.html
java/nio/file/DirectoryStream.Filter.html
javax/lang/model/type/DisjunctiveType.html
java/nio/file/attribute/DosFileAttributes.html
java/nio/file/attribute/DosFileAttributeView.html
java/sql/Driver.html
javax/lang/model/element/ElementKind.html
javax/lang/model/util/ElementKindVisitor6.html
javax/lang/model/util/ElementKindVisitor7.html
javax/lang/model/util/ElementScanner7.html
java/awt/EventQueue.html
java/beans/Expression.html
javax/net/ssl/ExtendedSSLSession.html
java/security/cert/Extension.html
java/beans/FeatureDescriptor.html
java/io/File.html
java/nio/file/FileAlreadyExistsException.html
java/nio/file/attribute/FileAttribute.html
java/nio/file/attribute/FileAttributeView.html
java/nio/channels/FileChannel.html
javax/swing/plaf/FileChooserUI.html
java/awt/FileDialog.html
java/nio/channels/FileLock.html
java/nio/file/attribute/FileOwnerAttributeView.html
java/nio/file/Files.html
java/nio/file/FileStore.html
java/nio/file/attribute/FileStoreAttributeView.html
java/nio/file/FileSystem.html
java/nio/file/FileSystemException.html
java/nio/file/FileSystemLoopException.html
java/nio/file/spi/FileSystemProvider.html
java/nio/file/FileSystems.html
java/nio/file/attribute/FileTime.html
java/nio/file/spi/FileTypeDetector.html
java/nio/file/FileVisitOption.html
java/nio/file/FileVisitor.html
java/nio/file/FileVisitResult.html
java/util/concurrent/ForkJoinPool.html
java/util/concurrent/ForkJoinTask.html
java/util/concurrent/ForkJoinWorkerThread.html
java/awt/GraphicsConfiguration.html
java/awt/GraphicsDevice.html
java/awt/GraphicsDevice.WindowTranslucency.html
java/util/GregorianCalendar.html
java/nio/file/attribute/GroupPrincipal.html
java/util/zip/GZIPOutputStream.html
javax/swing/text/html/HTMLFrameHyperlinkEvent.html
java/net/HttpURLConnection.html
javax/swing/event/HyperlinkEvent.html
java/nio/channels/IllegalChannelGroupException.html
java/util/IllformedLocaleException.html
java/net/InetAddress.html
java/net/InetSocketAddress.html
java/lang/Integer.html
java/nio/channels/InterruptedByTimeoutException.html
java/beans/Introspector.html
java/awt/event/InvocationEvent.html
java/dyn/InvokeDynamicBootstrapError.html
javax/swing/JLayer.html
javax/swing/JList.html
javax/swing/JSlider.html
javax/swing/text/JTextComponent.html
javax/swing/JTree.EmptySelectionModel.html
java/awt/event/KeyEvent.html
javax/swing/plaf/LayerUI.html
java/lang/LinkageError.html
java/util/concurrent/LinkedTransferQueue.html
java/nio/file/LinkOption.html
java/nio/file/LinkPermission.html
java/util/Locale.html
java/util/Locale.Builder.html
java/util/Locale.Category.html
java/util/spi/LocaleNameProvider.html
java/util/logging/Logger.html
java/lang/Long.html
java/lang/management/ManagementFactory.html
java/nio/channels/MembershipKey.html
javax/sound/midi/MetaMessage.html
javax/sound/midi/MidiDeviceReceiver.html
javax/sound/midi/MidiDeviceTransmitter.html
java/lang/reflect/Modifier.html
java/awt/event/MouseWheelEvent.html
java/nio/channels/MulticastChannel.html
java/nio/channels/NetworkChannel.html
java/net/NetworkInterface.html
javax/swing/plaf/nimbus/NimbusLookAndFeel.html
java/nio/file/NoSuchFileException.html
java/nio/file/NotDirectoryException.html
java/nio/file/NotLinkException.html
java/awt/font/NumericShaper.html
java/awt/font/NumericShaper.Range.html
java/util/Objects.html
java/nio/file/OpenOption.html
javax/lang/model/element/Parameterizable.html
java/nio/file/Path.html
java/nio/file/PathMatcher.html
java/nio/file/Paths.html
java/util/concurrent/Phaser.html
java/security/cert/PKIXReason.html
java/util/logging/PlatformLoggingMXBean.html
java/lang/management/PlatformManagedObject.html
java/nio/file/attribute/PosixFileAttributes.html
java/nio/file/attribute/PosixFileAttributeView.html
java/nio/file/attribute/PosixFilePermission.html
java/nio/file/attribute/PosixFilePermissions.html
java/lang/ProcessBuilder.html
java/lang/ProcessBuilder.Redirect.html
java/beans/PropertyChangeEvent.html
java/net/ProtocolFamily.html
java/sql/PseudoColumnUsage.html
javax/lang/model/element/QualifiedNameable.html
java/nio/channels/ReadPendingException.html
java/util/concurrent/RecursiveAction.html
java/util/concurrent/RecursiveTask.html
java/lang/ReflectiveOperationException.html
java/sql/ResultSet.html
javax/sql/rowset/RowSetFactory.html
javax/sql/rowset/RowSetProvider.html
java/util/Scanner.html
java/util/concurrent/ScheduledThreadPoolExecutor.html
java/awt/SecondaryLoop.html
java/nio/file/SecureDirectoryStream.html
java/nio/channels/SeekableByteChannel.html
java/nio/channels/spi/SelectorProvider.html
java/nio/channels/ServerSocketChannel.html
java/lang/Short.html
javax/sound/midi/ShortMessage.html
java/nio/channels/ShutdownChannelGroupException.html
javax/lang/model/util/SimpleAnnotationValueVisitor7.html
javax/lang/model/util/SimpleElementVisitor7.html
java/nio/file/SimpleFileVisitor.html
java/util/SimpleTimeZone.html
javax/lang/model/util/SimpleTypeVisitor7.html
java/nio/channels/SocketChannel.html
java/net/SocketOption.html
javax/lang/model/SourceVersion.html
javax/net/ssl/SSLEngine.html
javax/net/ssl/SSLParameters.html
javax/rmi/ssl/SslRMIServerSocketFactory.html
javax/net/ssl/SSLServerSocket.html
javax/net/ssl/SSLSocket.html
java/nio/file/StandardCopyOption.html
java/nio/file/StandardOpenOption.html
java/net/StandardProtocolFamily.html
java/net/StandardSocketOption.html
java/nio/file/StandardWatchEventKind.html
java/sql/Statement.html
javax/swing/border/StrokeBorder.html
javax/swing/SwingUtilities.html
javax/swing/plaf/synth/SynthButtonUI.html
javax/swing/plaf/synth/SynthCheckBoxMenuItemUI.html
javax/swing/plaf/synth/SynthCheckBoxUI.html
javax/swing/plaf/synth/SynthColorChooserUI.html
javax/swing/plaf/synth/SynthComboBoxUI.html
javax/swing/plaf/synth/SynthDesktopIconUI.html
javax/swing/plaf/synth/SynthDesktopPaneUI.html
javax/swing/plaf/synth/SynthEditorPaneUI.html
javax/swing/plaf/synth/SynthFormattedTextFieldUI.html
javax/swing/plaf/synth/SynthInternalFrameUI.html
javax/swing/plaf/synth/SynthLabelUI.html
javax/swing/plaf/synth/SynthListUI.html
javax/swing/plaf/synth/SynthLookAndFeel.html
javax/swing/plaf/synth/SynthMenuBarUI.html
javax/swing/plaf/synth/SynthMenuItemUI.html
javax/swing/plaf/synth/SynthMenuUI.html
javax/swing/plaf/synth/SynthOptionPaneUI.html
javax/swing/plaf/synth/SynthPanelUI.html
javax/swing/plaf/synth/SynthPasswordFieldUI.html
javax/swing/plaf/synth/SynthPopupMenuUI.html
javax/swing/plaf/synth/SynthProgressBarUI.html
javax/swing/plaf/synth/SynthRadioButtonMenuItemUI.html
javax/swing/plaf/synth/SynthRadioButtonUI.html
javax/swing/plaf/synth/SynthRootPaneUI.html
javax/swing/plaf/synth/SynthScrollBarUI.html
javax/swing/plaf/synth/SynthScrollPaneUI.html
javax/swing/plaf/synth/SynthSeparatorUI.html
javax/swing/plaf/synth/SynthSliderUI.html
javax/swing/plaf/synth/SynthSpinnerUI.html
javax/swing/plaf/synth/SynthSplitPaneUI.html
javax/swing/plaf/synth/SynthTabbedPaneUI.html
javax/swing/plaf/synth/SynthTableHeaderUI.html
javax/swing/plaf/synth/SynthTableUI.html
javax/swing/plaf/synth/SynthTextAreaUI.html
javax/swing/plaf/synth/SynthTextFieldUI.html
javax/swing/plaf/synth/SynthTextPaneUI.html
javax/swing/plaf/synth/SynthToggleButtonUI.html
javax/swing/plaf/synth/SynthToolBarUI.html
javax/swing/plaf/synth/SynthToolTipUI.html
javax/swing/plaf/synth/SynthTreeUI.html
javax/swing/plaf/synth/SynthUI.html
javax/swing/plaf/synth/SynthViewportUI.html
javax/sound/midi/SysexMessage.html
java/util/concurrent/ThreadLocalRandom.html
java/lang/Throwable.html
java/util/TimeZone.html
java/awt/Toolkit.html
java/util/concurrent/TransferQueue.html
java/beans/Transient.html
javax/lang/model/type/TypeKind.html
javax/lang/model/util/TypeKindVisitor7.html
javax/lang/model/util/Types.html
javax/lang/model/type/TypeVisitor.html
javax/lang/model/UnknownEntityException.html
java/net/URLClassLoader.html
java/nio/file/attribute/UserDefinedFileAttributeView.html
java/nio/file/attribute/UserPrincipal.html
java/nio/file/attribute/UserPrincipalLookupService.html
java/nio/file/attribute/UserPrincipalNotFoundException.html
java/nio/file/Watchable.html
java/nio/file/WatchEvent.html
java/nio/file/WatchEvent.Kind.html
java/nio/file/WatchEvent.Modifier.html
java/nio/file/WatchKey.html
java/nio/file/WatchService.html
java/awt/Window.html
java/awt/Window.Type.html
java/nio/channels/WritePendingException.html
java/dyn/WrongMethodTypeException.html
java/security/cert/X509CertSelector.html
java/security/cert/X509CRLEntry.html
javax/net/ssl/X509ExtendedTrustManager.html
java/beans/XMLDecoder.html
java/beans/XMLEncoder.html
java/util/zip/ZipFile.html
java/util/zip/ZipInputStream.html
java/util/zip/ZipOutputStream.html


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.

10 comments:

Martijn Verburg said...

Nice use of Groovy :). For me the most exciting features are NIO.2 and invokedynamic, can't wait to see what comes out of that bytecode instruction

Dustin said...

Java 7 Developer Blog has posts with additional in-depth coverage of JDK features such as try-with-resources and setting up NetBeans 7 with JDK 7.

Alex has posted twice on JDK 7 topics with focus on JDK 7 concurrency (JSR 166) and NIO.2 (JSR 203).

kellyrob said...

Indeed, nice Groovy script and a great heads up on Java 1.7 changes!
Was running a bit slow for me however, so I threw in some GPars goodness to kick it up a notch :)

https://gist.github.com/899826

Dustin said...

kellyrob,

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.

Thanks again for posting this enhanced code at https://gist.github.com/899826.

Dustin

Christian Ullenboom said...

http://javadiff.sourceforge.net/ would be a good idea.

Dustin said...

Christian,

Thanks for pointing out the existence of JDiff. I wasn't aware of this handy tool before your post.

Dustin

kellyrob said...

My pleasure Dustin, and thanks again for taking the time to share this info.

Matt Doar said...

Nice groovy work! I'm the author of JDiff and getting the complete API diff working was fiddly as I recall. I wish the Javadoc team would provide a tool to lead the way on this.

Dustin said...

Matt,

Thanks for the comment and for all the time and effort invested in JDiff.

JDiff is a great idea and something I was glad to learn about. I agree with you that it'd be nice to have an "official" or "standard" tool for doing these types of things.

Dustin

tutego Blog said...

You might like http://www.tutego.de/blog/javainsel/2011/07/enumerate-every-new-type-and-attribute-in-java-7-api-with-a-homebrewed-doclet/ too.