Java I/O, 2nd Edition


[ Table of Contents | Examples | Why I Like Writing for O'Reilly | Interview with Peter Wayner | Order ]

In many ways, this book is a prequel to my previous book, Java Network Programming. When writing that book, I more or less assumed that readers were familiar with basic input and output in Java—that they knew how to use input streams and output streams, convert bytes to characters, connect filter streams to each other, and so forth.

However, after that book was published, I began to notice that a lot of the questions I got from readers of the book and students in my classes weren’t so much about network programming itself as they were about input and output (I/O in programmer vernacular). When Java 1.1 was released with a vastly expanded java.io package and many new I/O classes spread out across the rest of the class library, it became obvious that a book that specifically addressed I/O was required. This is that book. More specifically it is that book updated and expanded to cover the even more impressive I/O capabilities introduced in Java 1.4, 5, and 6. The I/O class libraries in Java are more powerful and interesting than ever, and this book shows you how to take full advantage of them. Techniques you’ll learn here include:

Java is the first language to provide a cross-platform I/O library that is powerful enough to handle all these diverse tasks. Java is the first programming language with a modern, object-oriented approach to input and output. Java’s I/O model is more powerful and more suited to real-world tasks than any other major language used today. Java I/O is the first and still the only book to fully expose the power and sophistication of this library.

What’s New in The Second Edition

The first edition of this book was inspired by the wealth of I/O functionality added in Java 1.1, and this edition was in large part motivated by the new I/O packages introduced in Java 1.4. Therefore, this edition assumes you’re working with at least Java 1.4, though most of the basic material will work as far back as Java 1.1.

Java 1.4 introduced a huge amount of new material relevant to I/O. The most obvious additions are the java.nio packages that provide non-blocking and memory-mapped I/O. Chapters 14-16 cover these powerful new abilities in depth. java.nio also exposes character set conversion code that’s been present in the JDK since 1.1, but hasn’t had a public API before now. This is the primary subject of Chapter 19.

Many still relevant pre-1.4 topics have been added and expanded as well. The ProgressMonitorInputStream is covered here for the first time. Many more details are offered about object serialization including serialPersistentFields, writeReplace(), readResolve(), and javadoc tags for serialization. JAR files and the java.util.jar package now get their own chapter. Among other topics, I explain the Pack200 compression format and evangelize the increasingly popular technique of hiding non-code resources like images and data files inside JAR files.

Java 5 continues to build on the basic I/O functionality of Java 1.4 and earlier. Many new classes and methods from those versions are covered here including the Flushable and Closable interfaces. Most shockingly, Java 5 finally brings variable length argument lists and the printf family of functions, the lack of which helped inspire the first edition. You’ll find that these functions are even more powerful in Java than they are in C, and can handle not only numbers but also dates and several other object types.

I/O in Java isn’t finished evolving yet. Java 6 introduces some interesting new classes including Console and IOError. You’ll learn about these right up front in Chapter 1. Java 6 also introduces several other useful new methods including a much improved file system API that enables one to read the file attributes and determine the free space on a disk. Finally I added Swing’s FileSystemView, an oft-overlooked class that provides much information about the user’s view of the file system.

There’ve been many interesting developments outside the core JDK too. Some of the most exciting have happened in the world of small devices, both peripherals like GPS receivers that connect to a host computer and devices like Palm Pilots that are themselves increasingly powerful computers. Treatment of both of these has been dramatically expanded in this edition.

For those readers working with serial and parallel port devices, I’ve upgraded the Java Communications API chapter to version 3.0. However, in 2006 more and more devices use faster USB ports instead. Consequently the Chapter 23 covers the new Java USB API in depth. For smaller devices that can’t quite run full Java, but need to perform I/O nonetheless, J2ME offers the Generic Connection Framework (GCF). Chapter 24 covers this alternative to the traditional I/O framework. Chapter 25 uses the GCF to communicate over one of the newest I/O buses, the Bluetooth API used for wireless communications with a variety of peripherals.

Finally, the existing content has been rewritten from page 1 to bring it up to date with the latest thinking in Java code and style, as well as to make it clearer, more compact, and more accurate. For example, exception handling and multithreading is much improved in this edition’s examples. Streams are closed more reliably. Exceptions are thrown rather than caught where appropriate, and synchronization is avoided throughout. I expect you’ll find this edition even better than the first.

I'm really happy with this book. I do hope you'll check it out. It's available from amazon.com and other purveyors of fine computer books. If you need to special order it, the ISBN number is 0-596-52750-0. It's $49.99, published by O'Reilly, and written by me, Elliotte Rusty Harold.


[ Cafe au Lait | Examples | Why I Like Writing for O'Reilly | Interview | Order ]

Copyright 2006 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified September 7, 2006