The process of writing state of an object to a file is called Serialization but strictly speaking it is the process of converting an object from java supported form into either file supported form or neither supported form.
By using FileOutputStream and ObjectOutputStream classes we can implement Serialization.
The process of reading state of an object from the file is called Deserialization but strictly speaking it is the process of converting an object from either Filesupportedform or network supported form into java supported form.
By using FileInputStream and ObjectInputStream classes we can implement Deserialization.
We can serialize only serializable objects ,an object is said to be serializable if and only if the corresponding class implements Serializable(I) interface.
Serializable(I) interface present in java.io package and it doen't contain any methods it is a Marker Interface.
If we are trying to serialize a non serializable object then we will get RuntimeException saying NotSerializableException.
transient modifier(keyword)applicable only for variables but not for methods and classes.
At the time of serialization if we donít want to save the value of a particular variable to meet security constraints then we should declare that variable as transient.
While performing serialization JVM ignores original value of transient variable and save default value to the file.
Hence transient means not to serialize.
static variable is not part of object state and hence it wonít participate in serialization due to this declaring static variable as transient there is no use.
final variables will be participated in serialization directly by the value hence declaring a final variable as transient there is no impact.
We can serialize any number of objects to the file but in which order we serialiable in the same order only we have to deserialize i.e order of objects is serialization.
If we donít know order of objects in serialization:-