default: // FALLSTHROUGH
chars += tok.sval.length();
public static void main(String args[]) {
if (args.length == 0) { // We're working with stdin
try {
wc(new InputStreamReader(;
System.out.println(lines + " " + words + " " + chars);
} catch (IOException e) {};
} else { // We're working with a list of files
int twords = 0, tchars = 0, tlines = 0;
for (int i=0; i<args.length; i++) {
try {
words = chars = lines = 0;
wc(new FileReader(args[i]));
twords += words;
tchars += chars;
tlines += lines;
System.out.println(args[i] + ": " +
lines + " " + words + " " + chars);
} catch (IOException e) {
System.out.println(args[i] + ": error.");
System.out.println("total: " +
tlines + " " + twords + " " + tchars);
Serialization is the process of writing the state of an object to a byte stream. This is useful
when you want to save the state of your program to a persistent storage area, such as a file.
At a later time, you may restore these objects by using the process of deserialization.
Serialization is also needed to implement Remote Method Invocation (RMI). RMI allows
a Java object on one machine to invoke a method of a Java object on a different machine. An
object may be supplied as an argument to that remote method. The sending machine serializes
the object and transmits it. The receiving machine deserializes it. (More information about
RMI appears in Chapter 27.)
Assume that an object to be serialized has references to other objects, which, in turn,
have references to still more objects. This set of objects and the relationships among them
form a directed graph. There may also be circular references within this object graph. That
is, object X may contain a reference to object Y, and object Y may contain a reference back to
object X. Objects may also contain references to themselves. The object serialization and
deserialization facilities have been designed to work correctly in these scenarios. If you
attempt to serialize an object at the top of an object graph, all of the other referenced objects
Search WWH :
Custom Search
Previous Page
Java SE 6 Topic Index
Next Page
Java SE 6 Bookmarks