23.07.2013 Views

Java IO.pdf - Nguyen Dang Binh

Java IO.pdf - Nguyen Dang Binh

Java IO.pdf - Nguyen Dang Binh

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Who You Are<br />

<strong>Java</strong> I/O<br />

This book assumes you have a basic familiarity with <strong>Java</strong>. You should be thoroughly familiar<br />

with the syntax of the language. You should be comfortable with object-oriented<br />

programming, including terminology like instances, objects, and classes, and you should<br />

know the difference between these terms. You should know what a reference is and what that<br />

means for passing arguments to and returning values from methods. You should have written<br />

simple applications and applets.<br />

For the most part, I try to keep the examples relatively straightforward so that they require a<br />

minimum of understanding of other parts of the class library outside the I/O classes. This may<br />

lead some to deride these as "toy examples." However, I find that such examples are far more<br />

conducive to understanding and learning than full-blown sophisticated programs that fill page<br />

after page with graphical user interface code just to demonstrate a two-line point about I/O.<br />

Occasionally, however, a graphical example is simply too tempting to ignore, as in the<br />

StreamedTextArea class shown in Chapter 2 or the File Viewer application developed<br />

throughout most of the book. I will try to keep the AWT material to a minimum, but a<br />

familiarity with 1.1 AWT basics will be assumed.<br />

When you encounter a topic that requires a deeper understanding for I/O than is customary—<br />

for instance, the exact nature of strings—I'll cover that topic as well, at least briefly. However,<br />

this is not a language tutorial, and the emphasis will always be on the I/O-specific features.<br />

Versions<br />

In many ways, this book was inspired by the wealth of new I/O functionality included in <strong>Java</strong><br />

1.1. I/O in <strong>Java</strong> 1.0 is overall much simpler, though also much less powerful. For instance,<br />

there are no Reader and Writer classes in <strong>Java</strong> 1.0. However, there's also no reliable way to<br />

read pure Unicode text. Furthermore, <strong>Java</strong> 1.1 added many new classes to the library for<br />

performing a variety of I/O-related tasks like compression, encryption, digital signatures,<br />

object serialization, encoding conversion, and much more.<br />

Therefore, this book assumes at least <strong>Java</strong> 1.1. For the most part, <strong>Java</strong> 1.0 has been relegated<br />

to developing applets that run inside web browsers. Because the applet security manager<br />

severely restricts the I/O an untrusted applet can undertake, most applets do not make heavy<br />

use of I/O, and thus it should not be a major concern.<br />

<strong>Java</strong> 2's I/O classes are mostly identical to those in <strong>Java</strong> 1.1, with one noticeable exception.<br />

<strong>Java</strong> 2 does a much better (though still imperfect) job of abstracting out platform-dependent<br />

filesystem idiosyncrasies than does <strong>Java</strong> 1.1. Some (though not all) of these improvements are<br />

also available to <strong>Java</strong> 1.1 programmers working with Swing. I'll discuss both the <strong>Java</strong> 1.1 and<br />

<strong>Java</strong> 2 approaches to the filesystem in Chapter 12.<br />

In any case, when I discuss a method, class or interface that's only available in <strong>Java</strong> 2, its<br />

signature will be suffixed with a comment indicating that. For example:<br />

public interface Replaceable extends Serializable // <strong>Java</strong> 2<br />

8

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!