This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
Mahtab Alam wrote:
Cloning is making an exact copy of the object
and changes to one reflect changes in original object.
No. Changes to the values of the fields of one will not affect the other. However, in the default, "shallow copy" case, changes to the state of an object pointed to by the field of either object will be seen by the other.
But Serializing an object is like saving an object and making it alive when we need it
That's kind of right. The two main uses for serialization are to persist an object's state across JVM executions, and to transmit an object's state to another JVM over a network.
Cloning is used to make copy of an Object. Though changes in one will reflect changes in other, depending whether it is shallow copy or a deep copy.
Serialization on the other hand is used save the state of an Object. You will serialize an Object to get a stream and save it somewhere and de-serialize it to get your original Object(if that object doesn't contain any transient variable). Serialization is used majorly when you want to send an Object over the network or when you want to play with a pool of Object.