Using Serialization with a Custom Data Format

Abstract

Demonstrates how to use the writeObject and readObject methods to encode a custom data format. When there is a large amount of persistent data, that data should be stored in a convenient, condensed format, such as the one used in this example.

This example uses a triangular array, a symmetrical, 2-dimensional array. During serialization only half of the array is saved. This example serializes half of the array in writeObject, then restores the whole array in readObject by deserializing half of the array and copying to restore the other half of the array.

This example differs from the Using Serialization and the Serializable Fields API Example in that this example does not support versioning. In addition, because this example does not use an Externalizable interface, superclasses are not a consideration.

blue bar

Additional Information

Source Files
Running the Example
List of Examples

Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.