Search Tutorials

Top Java Serialization (2021) frequently asked interview questions | JavaInUse

Top Java Serialization frequently asked interview questions

In this post we will look at Java Serialization Interview questions. Examples are provided with explanation.

Q: What is Serialization?
Serialization can be defined as the process to make the object's state persistent. TO achieve this the state of the object is written into byte stream. This is used usually when we need to save the object in database using JPA, sending object to JMS etc. Serialization is implemented using writeObject() method ObjectOutputStream.

Q: What is Deserialization?
Deserialization is the process of retrieving the objects state from the byte stream. It is the oppposite of Serialization. Deserialization is implemented using readObject() method ObjectOutputStream

Q: What is a serialVersionUID and why should I use it?
Each serializable class has a version numberber associated with it, this is called serialVersionUID. A serializable class declares it's own serialVersionUID by declaring a field named serialVersionUID which must be static, final, and of type long. The main objective of using serialVersionUID is to verify that the sender and receiver of a serialized object have loaded classes for that object that are compatible with respect to serialization. If this is not the case then an exception of type InvalidClassException.

Q: What is the difference between Serialization and Marshaling?
Marshalling is the process of converting an object into JSON/XML to get parameters, while serialization is the process of converting an object to byte stream to save it's state.

Q: Why does Java have transient fields?
The transient keyword in Java is used to indicate that a field should not be part of the serialization process. So such fields are not part of the objects state that gets saved during serialization.

See Also

Spring Batch Interview Questions Apache Camel Interview Questions JBoss Fuse Interview Questions Drools Interview Questions Java 8 Interview Questions