What is meant by \"object serialization\"? Can you please explain it with some examples?
|*| Serializing a class : Converting an object to bytes and bytes back to object (Deserialization).
class NamCls implements Serializable
{
int NumVar;
String NamVar;
}
|=> Object-Serialization is process of converting the state of an object into steam of bytes.
|=> Object-Deserialization is the process of getting the state of an object and store it into an object(java.lang.Object).
|=> A Java object is only serializable, if its class or any of its superclasses
|=> Static fields in a class cannot be serialized.
class NamCls implements Serializable
{
int NumVar;
static String NamVar = "I won't be serializable";;
}
|=> If you do not want to serialise a variable of a class use transient keyword
class NamCls implements Serializable
{
int NumVar;
transient String NamVar;
}
|=> If a class implements serializable then all its sub classes will also be serializable.
|=> If a class has a reference of another class, all the references must be Serializable otherwise serialization process will not be performed. In such case,
NotSerializableException is thrown at runtime.