Java 7 New Features Cookbook

Java 7 New Features Cookbook
eBook: $23.99
Formats: PDF, PacktLib, ePub and Mobi formats
save 15%!
Print + free eBook + free PacktLib access to the book: $63.98    Print cover: $39.99
save 37%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Table of Contents
Sample Chapters
  • Comprehensive coverage of the new features of Java 7 organized around easy-to-follow recipes
  • Covers exciting features such as the try-with-resources block, the monitoring of directory events, asynchronous IO and new GUI enhancements, and more
  • A learn-by-example based approach that focuses on key concepts to provide the foundation to solve real world problems

Book Details

Language : English
Paperback : 384 pages [ 235mm x 191mm ]
Release Date : February 2012
ISBN : 1849685622
ISBN 13 : 9781849685627
Author(s) : Richard M. Reese, Jennifer L. Reese
Topics and Technologies : All Books, Application Development, Cookbooks, Enterprise, Java

Table of Contents

Chapter 1: Java Language Improvements
Chapter 2: Locating Files and Directories Using Paths
Chapter 3: Obtaining File and Directory Information
Chapter 4: Managing Files and Directories
Chapter 5: Managing Filesystems
Chapter 6: Stream IO in Java 7
Chapter 7: Graphical User Interface Improvements
Chapter 8: Handling Events
Chapter 9: Database, Security, and System Enhancements
Chapter 10: Concurrent Processing
Chapter 11: Odds and Ends
  • Chapter 1: Java Language Improvements
    • Introduction
    • Using string literals in switch statements
    • Using underscores in literals to improve code readability
    • Using the try-with-resources block to improve exception handling code
    • Creating a resource that can be used with the try-with-resources technique
    • Catching multiple exception types to improve type checking
    • Rethrowing exceptions in Java 7
    • Using the diamond operator for constructor type inference
    • Using the @SafeVarargs annotation
    • Chapter 2: Locating Files and Directories Using Paths
      • Introduction
      • Creating a Path object
      • Interoperability between and java.nio.file.Files
      • Converting a relative path into an absolute path
      • Removing redundancies by normalizing a path
      • Combining paths using path resolution
      • Creating a path between two locations
      • Converting between path types
      • Determining whether two paths are equivalent
      • Managing symbolic links
      • Chapter 3: Obtaining File and Directory Information
        • Introduction
        • Determining the file content type
        • Obtaining a single attribute at a time using the getAttribute method
        • Obtaining a map of file attributes
        • Getting file and directory information
        • Determining operating system support for attribute views
        • Maintaining basic file attributes using the BasicFileAttributeView
        • Maintaining POSIX file attributes using the PosixFileAttributeView
        • Maintaining FAT table attributes using the DosFileAttributeView
        • Maintaining file ownership attributes using the FileOwnerAttributeView
        • Maintaining a file's ACL using the AclFileAttributeView
        • Maintaining user-defined file attributes using the UserDefinedFileAttributeView
        • Chapter 4: Managing Files and Directories
          • Introduction
          • Creating files and directories
          • Controlling how a file is copied
          • Managing temporary files and directories
          • Setting time-related attributes of a file or directory
          • Managing file ownership
          • Managing ACL file permissions
          • Managing POSIX attributes
          • Moving a file and a directory
          • Deleting files or directories
          • Managing symbolic links
          • Chapter 5: Managing Filesystems
            • Introduction
            • Getting FileStore information
            • Getting Filesystem information
            • Using the SimpleFileVisitor class to traverse filesystems
            • Deleting a directory using the SimpleFileVisitor class
            • Copying a directory using the SimpleFileVisitor class
            • Processing the contents of a directory by using the DirectoryStream interface
            • Filtering a directory using globbing
            • Writing your own directory filter
            • Monitoring file events using WatchEvents
            • Understanding the ZIP filesystem provider
            • Chapter 6: Stream IO in Java 7
              • Introduction
              • Managing simple files
              • Using buffered IO for files
              • Random access IO using the SeekableByteChannel
              • Managing asynchronous communication using the AsynchronousServerSocketChannel class
              • Writing to a file using the
              • AsynchronousFileChannel class
              • Reading from a file using the
              • AsynchronousFileChannel class
              • Using the SecureDirectoryStream class
              • Chapter 7: Graphical User Interface Improvements
                • Introduction
                • Mixing heavyweight and lightweight components
                • Managing window types
                • Managing the opacity of a window
                • Creating a varying gradient translucent window
                • Managing the shape of a window
                • Using the new border types in Java 7
                • Handling multiple file selection in the FileDialog class
                • Controlling the print dialog box type
                • Using the new JLayer decorator for a password field
                • Chapter 8: Handling Events
                  • Introduction
                  • Managing extra mouse buttons and high resolution mouse wheels
                  • Controlling a focus when displaying a window
                  • Using secondary loops to mimic modal dialog boxes
                  • Handling spurious thread wakeups
                  • Handling applet initialization status with event handlers
                  • Chapter 9: Database, Security, and System Enhancements
                    • Introduction
                    • Using the RowSetFactory class
                    • Java 7 database enhancements
                    • Using the ExtendedSSLSession interface
                    • Using the platform MXBeans for JVM or system process load monitoring
                    • Redirecting input and output from operating system's processes
                    • Embedding a JNLP file in an HTML page
                    • Chapter 10: Concurrent Processing
                      • Introduction
                      • Using join/fork framework in Java
                      • Using the reusable synchronization barrier Phaser
                      • Using the new ConcurrentLinkedDeque safely with multiple threads
                      • Using the new LinkedTransferQueue class
                      • Supporting multiple threads using the ThreadLocalRandom class
                      • Chapter 11: Odds and Ends
                        • Introduction
                        • Handling weeks in Java 7
                        • Using the Currency class in Java 7
                        • Using the NumericShaper.Range enumeration to support the display of digits
                        • JavaBean enhancements in Java 7
                        • Handling locales and the Locale.Builder class in Java 7
                        • Handling null references
                        • Using the new BitSet methods in Java 7

                        Richard M. Reese

                        Richard M. Reese holds a Ph.D. in Computer Science from Texas A & M University and is currently an Associate Professor in the Department of Engineering and Physics at Tarleton State University in Stephenville, Texas. In addition to his experience in academia, Richard has over 17 years experience in industry including operating system development at GTE Automatic Electric Labs and at Lockheed Martin in Fort Worth, Texas, where he supervised a tool development group and oversaw various research and development projects. Prior to his industrial experience he served four years in the United States Air Force. Richard has been involved with Java since 1996 and is a certified Java SE 7 Associate Programmer. He has worked as consultant/instructor of software languages in private and public classes providing him with a variety of insight into industry applications. He has published numerous papers and has developed courseware for a variety of topics including advanced Java technologies. He has also written the EJB 3.1 Cookbook and Java 7 New Features Cookbook for Packt Publishing.

                        Jennifer L. Reese

                        Jennifer L. Reese holds a B.S. degree from Tarleton State University. She currently works as a software engineer for Local Government Solutions in Waxahachie, Texas, developing software for county government. Prior to graduation, she worked for the Center for Agribusiness Excellence at Tarleton where she used Java in conjunction with GIS software to analyze crop and weather data.
                        Sorry, we don't have any reviews for this title yet.

                        Code Downloads

                        Download the code and support files for this book.

                        Submit Errata

                        Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.


                        - 2 submitted: last submission 29 Oct 2012

                        Errata type: Code | Page number: 351 | Errata date: 11 Oct 2012

                        Code fragment is syntactically incorrect

                        while (())String item: list {



                        The while statement should appear as

                        ListIterator list = returnEmptyListIterator();

                        while(list.hasNext()) {

                        String item =;



                        Errata type: Typo | Page number: 38 | Errata date: 24 Oct 2012

                        The line, "At run-time, this will manifest itself as an unchecked warning"

                        should read

                        "At compile-time, this will manifest itself as an unchecked warning"

                        Sample chapters

                        You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

                        Frequently bought together

                        Java 7 New Features Cookbook +    Microsoft SharePoint 2010 Administration Cookbook =
                        50% Off
                        the second eBook
                        Price for both: €24.20

                        Buy both these recommended eBooks together and get 50% off the cheapest eBook.

                        What you will learn from this book

                        • Use new Java language improvements such as improved exception handling techniques and better support for literals
                        • Manage files and directories using the new Path class for better control of file attributes and special files such as symbolic links
                        • Manage file systems traversals and monitor directory and files changes
                        • Perform asynchronous IO in Java 7 and treat a zip file as a file system to ease the use of zip files
                        • Use the numerous Graphical User Interface improvements including window methods, the new JLayer class and various dialog box-related methods
                        • Utilize improved access to mouse buttons and the mouse wheel along with additional event handling support
                        • Master the new row set interfaces and control of the database schema
                        • Use new techniques for interacting with operating system processes and improvement in SSL session support
                        • Manage threads using the join/fork paradigm and use new data structures with threads
                        • Incorporate numerous development techniques such as support for locale and currency and the ability to handle null pointers


                        In Detail

                        Java 7 is a major update that includes a lot of exciting new language improvements such as support for type inference and improved exception handling. Other new features include the ability to work with symbolic links, a greatly simplified directory traversal technique, and the monitoring of file creation and deletion. Improvements in event handling, security, and concurrent processing have also been added

                        Java 7 New Features Cookbook is your go-to guide to learn about all the new exciting features Java 7 has to offer with a very practical recipe-based approach.

                        The book starts with coverage of the new language improvements. Subsequent chapters address the new features of Java 7 while incorporating these new language improvements when possible.

                        The new NIO techniques provide enhanced capabilities which are complemented by the new try-with-resources block and enhanced generic support. The new JLayer decorator and improved window methods enhance the developer’s ability to create GUI applications.

                        The Java 7 New Features Cookbook provides a comprehensive coverage of the exciting features in Java 7.


                        Each recipe comprises step-by-step instructions followed by an analysis of what was done in each task and other useful information. The book is designed so that you can read it chapter by chapter, or look at the list of recipes and refer to them in no particular order. Each example comes with its expected output to make your learning even easier.

                        Who this book is for

                        This book is designed to bring those who are familiar with Java up-to-speed on the new features found in Java 7.

                        Code Download and Errata
                        Packt Anytime, Anywhere
                        Register Books
                        Print Upgrades
                        eBook Downloads
                        Video Support
                        Contact Us
                        Awards Voting Nominations Previous Winners
                        Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
                        Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software