Serialization – The why part
Recently I was interacting with some of my folks and find that mostly they have used serialization but have not realized much. And I thought, I can also learn different views from my blog readers (Trust me there are some ) by posting my views. So my definition, here you go.
As all of you know, Class is nothing but a complex data type represents real world objects with the help of primitive data types. Grouping primitive data and bringing meaningful definition. When you transferring an object from machine to A to B, litteraly the object will be recreated (Nobody can make magic here. The newly created object would be created in a new memory location and will be initialized with the same state (the values) what the object was holding in machine A.
What is serialization?
“Streaming your class state over wire”
Why do you need serialization?
Say you want to transfer an object (naturally with some state otherwise will you call as object? thats class right?) to machine A to machine B, how do you that? Serialization converts the state to binary.
What is Marshalling and Un-marshalling?
If you look into deeper the serialization, its Marshalling and Un-marshalling. Marshalling – The process converts state to binary and Un-marshalling does the vice versa.
Java provides default implementation, geeks can have their own algorithm to customize this process.
Sometimes if you dont need to transfer the state of a particular data member then you can declare that variable as transient variable and make Java life simpler. When object is being created at other end the transient data member will be initialized by default value.
In my next post, lets see my views on the PMD rule BeanMembersShouldSerialize and the decision I have taken.
Folks, feel free to redefine, extend or agree my views on serialization.