Java Reference
In-Depth Information
Beforeserializinganobject,theserializationmechanismcheckstheobject'sclassto
seeifitimplements Externalizable .Ifso,themechanismcalls writeExtern-
al() . Otherwise, it looks for a private writeObject(ObjectOutputStream)
method, and calls this method if present. If this method isn't present, the mechanism
performs default serialization, which includes only non- transient instance fields.
Before deserializing an object, the deserialization mechanism checks the object's
class to see if it implements Externalizable . If so, the mechanism attempts to
instantiate the class via the public noargument constructor. Assuming success, it calls
readExternal() .
If the object's class doesn't implement Externalizable , the deserialization
mechanism looks for a private readObject(ObjectInputStream) method. If
this method isn't present, the mechanism performs default deserialization, which in-
cludes only non- transient instance fields.
PrintStream
Of all the stream classes, PrintStream is an oddball: it should have been named
PrintOutputStream forconsistencywiththenamingconvention.Thisfilteroutput
stream class writes string representations of input data items to the underlying output
stream.
Note PrintStream uses the default character encoding to convert a string's
characters to bytes. (I'll discuss character encodings when I introduce you to writers
and readers in the next section.) Because PrintStream doesn't support different
character encodings, you should use the equivalent PrintWriter class instead of
PrintStream . However, you need to know about PrintStream when working
with System.out and System.err because these class fields are of type
PrintStream .
PrintStream instances are print streams whose various print() and
println() methods print string representations of integers, floating-point values,
and other data items to the underlying output stream. Unlike the print() methods,
println() methods append a line terminator to their output.
Note Thelineterminator(alsoknownaslineseparator)isn'tnecessarilythenewline
(alsocommonly referredtoaslinefeed).Instead,topromoteportability,thelinesep-
arator is the sequence of characters defined by system property line.separator .
On Windows platforms, System.getProperty("line.separator") returns
Search WWH ::




Custom Search