javaoopobjectserializationstream

What is the purpose of Serialization in Java?


I have read quite a number of articles on Serialization and how it is so nice and great but none of the arguments were convincing enough. I am wondering if someone can really tell me what is it that we can really achieve by serializing a class?


Solution

  • Let's define serialization first, then we can talk about why it's so useful.

    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, and the internal state of the object. This byte array can then be used between JVM's running the same code to transmit/read the object.

    Why would we want to do this?

    There are several reasons: