285
13 I/O, Applets, and Other Topics
13 I/O, Applets, and Other Topics
T
his chapter introduces two of Java’s most important packages:ioandapplet. Theio
package supports Java’s basic I/O (input/output) system, including file I/O. Theapplet
package supports applets. Support for both I/O and applets comes from Java’s core
API libraries, not from language keywords. For this reason, an in-depth discussion of these
topics is found in Part II of this book, which examines Java’s API classes. This chapter discusses
the foundation of these two subsystems so that you can see how they are integrated into the
Java language and how they fit into the larger context of the Java programming and execution
environment. This chapter also examines the last of Java’s keywords:transient,volatile,
instanceof,native,strictfp,andassert. It concludes by examining static import and by
describing another use for thethiskeyword.
I/O Basics
As you may have noticed while reading the preceding 12 chapters, not much use has been
made of I/O in the example programs. In fact, aside fromprint( )andprintln( ), none of the
I/O methods have been used significantly. The reason is simple: most real applications of
Java are not text-based, console programs. Rather, they are graphically oriented programs that
rely upon Java’s Abstract Window Toolkit (AWT) or Swing for interaction with the user.
Althoughtext-based programs are excellent as teaching examples, they do not constitute an
important use for Java in the real world. Also, Java’s support for console I/O is limited and
somewhat awkward to use—even in simple example programs. Text-based console I/O is
just not very important to Java programming.
The preceding paragraph notwithstanding, Java does provide strong, flexible support
for I/O as it relates to files and networks. Java’s I/O system is cohesive and consistent. In
fact, once you understand its fundamentals, the rest of the I/O system is easy to master.