Serialization
Serialization
is simply turning an existing object into a byte array.
This byte array
represents:
· The class
of the object
· The
version of the object
This byte array can then
be used between JVM's running the same code to transmit/read the object,
Serialization is used in below cases:
·
Persistence:
If you want to store the state of a
particular operation in a database, it can be easily serialized to a
byte array, and stored in the database for later retrieval.
· Deep Copy:
If you need an exact replica of an Object,
and don't want to go to the trouble of writing your own specialized clone()
class, simply serializing the object to a byte array, and then de-serializing
it to another object achieves this goal.
· Caching:
Really just an application of the above, but sometimes an object takes 10
minutes to build, but would only take 10 seconds to de-serialize. So, rather than hold onto the giant object in memory,
just cache it out to a file via serialization, and read it in later when
it's needed.
· Cross JVM Synchronization:
Serialization works across different JVMs that may be running on different
architectures.
No comments:
Post a Comment