Java serialization is the process which is used to serialize object in java by storing object’s state into a file with extension .ser and recreating object's state from that file, this reverse process is called deserialization.
Serializable and Externalizable interface is used to implement serialization functionality.
1) How to make a Java class Serializable?.
Your Java class just needs to implements java.io.Serializable Interface.
2) What is the difference between Serializable and Externalizable interface in Java?
Serializable -- > marker interface --> default serialization
writeExternal() and readExternal() method which gives us flexibility to control java serialization mechanism instead of relying on Java's default serialization
3) What is serialVersionUID? What would happen if you don't define this?
SerialVersionUID is a unique identifier for each class, JVM uses it to compare the versions of the class ensuring that the same class was used during Serialization is loaded during Deserialization.
4) While serializing you want some of the members not to serialize? How do you achieve it?
Either static or transient
5) If a class is Serializable but its super class in not, what will be the state of the instance variables inherited from super class after deserialization?
6) What will happen if one of the members in the class doesn't implement Serializable interface?
If you try to serialize an object of a class which implements serializable, but the object includes a reference to an non-serializable class then a ‘NotSerializableException’ will be thrown at runtime.
7) ObjectOutputStream --> writeObject() --> make it serializable.
ObjectInputStream --> readObject --> for deserialization process
Serializable and Externalizable interface is used to implement serialization functionality.
1) How to make a Java class Serializable?.
Your Java class just needs to implements java.io.Serializable Interface.
2) What is the difference between Serializable and Externalizable interface in Java?
Serializable -- > marker interface --> default serialization
writeExternal() and readExternal() method which gives us flexibility to control java serialization mechanism instead of relying on Java's default serialization
3) What is serialVersionUID? What would happen if you don't define this?
SerialVersionUID is a unique identifier for each class, JVM uses it to compare the versions of the class ensuring that the same class was used during Serialization is loaded during Deserialization.
4) While serializing you want some of the members not to serialize? How do you achieve it?
Either static or transient
5) If a class is Serializable but its super class in not, what will be the state of the instance variables inherited from super class after deserialization?
6) What will happen if one of the members in the class doesn't implement Serializable interface?
If you try to serialize an object of a class which implements serializable, but the object includes a reference to an non-serializable class then a ‘NotSerializableException’ will be thrown at runtime.
7) ObjectOutputStream --> writeObject() --> make it serializable.
ObjectInputStream --> readObject --> for deserialization process
No comments:
Post a Comment