Download Object Serialization for Programming Language Technology and Paradigms | CMSC 433 and more Study notes Programming Languages in PDF only on Docsity!
Object Serialization
Say you have a bunch of data
That you want to:
Save to a file, or
Send over a tcp connection
What are your options
Structured data
What if you want to send structured data? - E.g., a HashMap from Strings to integers
Or even more complicated stuff
A sequence of commands to an IMAP server
A graph
Options
Develop a text based format
Designed for human readability
Designed for machine readability (e.g., XML)
Some binary format
Custom, or
VM / library generated
Java object serialization
You can decorate any OutputStream with an ObjectOutputStream - Allows you to write ints, floats, longs, … - And (Serializable) Objects
Decorate an InputStream with an ObjectInputStream to read it in
Many things are serializable
Strings, Integers, most collections
Although a collection can only be serialized if the things contained in the collection are serializable
You can make your own classes serializable
Cycles
Graphs and cycles are
handled
Object serialization handles graphs and cycles - When reconstructed, object graph is isomorphic to original