Monday, August 4

Concept of Serialization

 What is Serialization?

Serialization is an API for encoding an objects as byte-stream and reconstructing objects from their byte-stream encodings. The serializing is process of encoding objects as byte-stream and reverse process is called deserializing.

Implementation Of Serializable

Implementation Serializable to an object allow's class instances to be serialized can be as simple as adding the words 'implements Serializable' to its declaration.


 Code Snippet :


What is Serialize?

Serializable is a marker interfaces that tells the JVM it can write out the state of the object to some stream (basically read all the members, and write out their state to a stream, or to disk or something). The default mechanism is a binary format. You can also use it to clone things, or keep state between invocations, send objects across the network etc. 
 Note : Do not implement Serializable lightly, since it restricts future flexibility, and publicly exposes class implementation details which are usually private. As well, implementing Serializable correctly is not trivial.
The ObjectOutputStream class and the ObjectInputStream class implement the ObjectOutput interface and the ObjectInput interface, respectively, providing methods to write and read binary representation of objects as well as Java primitive values. An overview of how these classes can be chained to underlying streams and some selected methods they provide. The figure does not show the methods inherited from the abstract OutputStream and InputStream superclasses.



Serializing and deserializing an object.

 






No comments:

Post a Comment

Ads Inside Post