Simple answer to this one is that Serialization is the process by which Objects are converted into a stream of bytes. For this we just need to implement the class which we want to serialize by the marker interface (Marker interface is a one which contains no methods). Typical usage of serialization is to store object state on local desk or send it across over a network.
Java Serial Unique Identifier (or serialVersionUID) is used for versioning of Java Classes. Whenever you perform validation it is recommended that you declare value of serialVersionUID manually (Otherwise Java creates it on it's own while compiling). This ensures that if we make any changes in the Java class, we could avoid a "ClassNotCompatibleError" during runtime while de-serializing the class.
Some other common questions related to Serialization
- Static fields in a class do not get serialized as we are serializing an object and not a class.
- Externalizable is another interface in Java used for serialization, giving us the flexibility of customizing serializing/de-serializing the object by giving us the flexibilty of overriding the methods readObject and writeObject
No comments:
Post a Comment