Serialization in Java

Serialization in Java : The process of converting java supported file data to network supported file data is called as “Serialization”.
And process of converting network supported file data to Java supported file data is called as “De-serialization”.
To achieve serialization your class must implements Serializable interface.
If parent class implements Serializable interface then child class doesn’t need to implement it and vice versa.
Object class doesn’t implements Serializable interface by default, if it does then there was no need to implement Serializable interface explicitly to all other classes (as object class is a parent class of all classes in Java).

Serialization in Java

Transient Keyword in Serialization:
It is applicable for variables only.
At the time of serialization if we don’t want to save the value of particular variable to meet security constraints then we should make that variable as transient.
Because at the time of serialization JVM ignores the original value and will save the default value of that transient variable.
In short transient means not to serialize.


Static and Static Transient:

Static variable are not the part of object and hence they will not participate in serialization.
So declaring a static variable as transient makes no sense. There will not be any impact.


Final Transient:
Final variable will be participated in serialization directly by their value.
So declaring final variable as transient makes no sense. There will not be any impact.

Serialization in Java

Thanks for visiting Ajitation.com, Ajitation is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content.