Exercise 10: Serialization

Fraction implements Serializable. 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 | Cafe au Lait

Copyright 2005 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified November 11, 2005