Wednesday Sep 09, 2015

Java 8 in Practice!

How can you use the new features of Java 8 in your day-to-day programming? In the article “Java SE 8 in Practice”,  Trisha Gee explores some specific Java SE 8 features such as lambda expressions and the Stream API to easily perform common operations, such as mapping, sorting, comparing, and working with files. 

Trisha demonstrates with live code how to create leaderboard of top tweeters, a map with key entry for every new handle and a user for each key. She compares before and after Java SE 8 and describes how IntelliJ IDEA is useful for programmers to bridge the gap between their current Java knowledge and the new succinct syntax of method references. To rank users into the leaderboard, she sorts them according to the number of times they’ve tweeted using the sorted() method on Stream. The application creates a bar chart representing a range of streamed data over time using the new Data and Time API. Next she touches on file handling in Java 8 SE to parse a file that contains tweets, demonstrating the nice integration between Java 8 streams and Java SE 7 I/O. Finally, she demonstrates parsing the tweets using more advanced Stream API methods in the “tweet mood analyzer” part of her application.

“Java SE 8 is more than just a bit of extra syntax to learn or a couple of new methods that might be useful. It can change the way we approach solving common problems,” she explains. Find the full article here

Thursday Jan 19, 2012

A File I/O Tutorial Featuring NIO.2

A tutorial on the front page of otn/java titled “A File I/O Tutorial Featuring NIO.2” explains the new file I/O mechanism introduced in the Java 7 release. The java.nio.file package and its related package, java.nio.file.attribute, provide comprehensive support for file I/O and for accessing the default file system. Though the API has many classes, developers need only focus on a few key entry points. The tutorial makes it clear that the API is intuitive and easy to use.

The tutorial begins by asking, “What is a path?” and then introduces the Path class, which is the primary entry point for the package. It explains Methods in the Path class related to syntactic operations and moves on to the other primary class in the package, the Files class, which contains methods related to file operations. It then introduces some concepts common to many file operations and explains methods for checking, deleting, copying, and moving files.

The tutorial offers a concise summary of the API with suggestions for further learning.

“The java.nio.file package provides extensive support for file and file system I/O. This is a very comprehensive API, but the key entry points are as follows:
•    The Path class has methods for manipulating a path.
•    The Files class has methods for file operations, such as moving, copy, deleting, and also methods for retrieving and  setting file attributes.
•    The FileSystem class has a variety of methods for obtaining information about the file system.”

More information on NIO.2 can be found on the OpenJDK: NIO project website on This site includes resources for features provided by NIO.2 that are beyond the scope of this tutorial, such as multicasting, asynchronous I/O, and creating your own file system implementation.

Read the complete article here.


Insider News from the Java Team at Oracle!



« June 2016