Exercise 11: Serialization

Write a test that serializes and deserializes a Fraction object; That is:

  1. Create a Fraction

  2. Create a ByteArrayOutputStream

  3. Chain an ObjectOutputStream to the ByteArrayOutputStream

  4. Write the Fraction object onto the ObjectOutputStream using writeObject()

  5. Close the ObjectOutputStream

  6. Get a byte array from the ByteArrayOutputStream using toByteArray()

  7. Make a ByteArrayInputStream from the byte array

  8. Chain an ObjectInputStream to the ByteArrayInputStream

  9. Read the object from the ObjectInputStream using readObject()

  10. Verify that the object is equal to but not the same as the original object

Previous | Next | Top | Cafe con Leche

Copyright 2005-2007 Elliotte Rusty Harold
Last Modified January 28, 2007