Skip to Main Content
Java I/O, 2nd Edition
book

Java I/O, 2nd Edition

by Elliotte Rusty Harold
May 2006
Beginner to intermediate content levelBeginner to intermediate
726 pages
19h 57m
English
O'Reilly Media, Inc.
Content preview from Java I/O, 2nd Edition

Chapter 13. Object Serialization

The last several chapters have shown you how to read and write Java’s fundamental data types (byte, int, String, etc.). However, there’s been one glaring omission. Java is an object-oriented language, and yet aside from the special case of strings, you haven’t seen any general-purpose methods for reading or writing objects.

Object serialization, first used in the context of Remote Method Invocation (RMI) and later for JavaBeans, addresses this need. The java.io.ObjectOutputStream class provides a writeObject( ) method you can use to write a Java object onto a stream. The java.io.ObjectInputStream class has a readObject( ) method that reads an object from a stream. ObjectInputStream and ObjectOutputStream implement the DataInput and DataOutput interfaces respectively so they can also write primitive data types such as ints, floats, and doubles, In this chapter you’ll learn how to use these two classes to read and write objects as well as how to customize the format used for serialization.

Reading and Writing Objects

Object serialization saves an object’s state in a sequence of bytes so that the object can be reconstituted from those bytes at a later time. Serialization in Java was first developed for use in RMI. RMI allows an object in one virtual machine to invoke methods in an object in another virtual machine, possibly in a different computer on the other side of the planet, by sending arguments and return values across the Internet. This requires ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java I/O

Java I/O

Elliotte Rusty Harold
Java NIO

Java NIO

Ron Hitchens

Publisher Resources

ISBN: 0596527500Errata PageSupplemental Content