Basic HTML version of Foils prepared Sept 21 1998

Foil 40 Object Serialization

From Java Tutorial 98- 4: Multi-Treading, Useful Java Classes, I/O and Networking NAVO Tutorial -- Sept 23 1998. by Geoffrey C. Fox, Nancy McCracken


1 ObjectInputStream and ObjectOutputStream allows you to read and write objects from any class (not just primitive types).
2 Java objects are serialized with writeObject() and deserialized with readObject(). For example:
  • Vector lines = new Vector( 256 ); ...
  • try {
  • new ObjectOutputStream(
  • new GZIPOutputStream(
  • new FileOutputStream( filename ) ) );
  • out.writeObject( lines );
  • out.close();
  • } catch ( IOException e ) { }
3 Only objects of classes that implement Serializable (or Externalizable) can be serialized. (The Serializable interface defines no methods.)
4 Object variables not to be serialized are called transient.

in Table To:


© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Sat Nov 28 1998