Contents
Why serialization and deserialization is required?
Serialization is the process of converting an object into a stream of bytes to store the object or transmit it to memory, a database, or a file. Its main purpose is to save the state of an object in order to be able to recreate it when needed. The reverse process is called deserialization.
What role does serialization deserialization play in OOP?
The serialization changes the object state into series of bits. The object state could be reconstructed later in the opposite process, called deserialization or unmarshalling . The reconstructed object is a semantically identical clone to the original object. The object after serialization is called archive .
Why is deserialization important?
After a serialized object has been written into a file, it can be read from the file and deserialized that is, the type information and bytes that represent the object and its data can be used to recreate the object in memory.
How do you achieve serialization and deserialization?
For serializing the object, we call the writeObject() method of ObjectOutputStream class, and for deserialization we call the readObject() method of ObjectInputStream class. We must have to implement the Serializable interface for serializing the object.
What is the difference between serialization and deserialization?
Serialization is used to export application data into a file. The destination application then uses deserialization to extract the data from the application for further use. Serialization is a concept in which C# class objects are written or serialized to files. Let’ say you had a C# class called Tutorial.
How is the serialversionuid used in deserialization?
The serialVersionUID is a universal version identifier for a Serializable class. Deserialization uses this number to ensure that a loaded class corresponds exactly to a serialized object. If no match is found, then an InvalidClassException is thrown.
What do you need to know about serialization in Java?
If class-specific initialization is needed, the class may provide a readObject method that can initialize the field to non default values. Adding classes – The stream will contain the type hierarchy of each object in the stream. Comparing this hierarchy in the stream with the current class can detect additional classes.
Which is the reverse process of deserialization in Java?
Deserialization is the reverse process where the byte stream is used to recreate the actual Java object in memory. This mechanism is used to persist the object.