This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes Cloning and Serialization ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Cloning and Serialization ?" Watch "Cloning and Serialization ?" New topic
Author

Cloning and Serialization ?

Mahtab Alam
Ranch Hand

Joined: Mar 28, 2012
Posts: 249

What is the difference between Cloning and Serialization.

It seems almost same.


What i know:
Cloning is making an exact copy of the object and changes to one reflect changes in original object.


But Serializing an object is like saving an object and making it alive when we need it.

Please add anything if you like.......


Oracle Java Programmer , Oracle SQL Expert , Oracle Java Web Component Developer
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Mahtab Alam wrote:
Cloning is making an exact copy of the object


Yes.

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.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38472
    
  23
The two are very different. Serialisation means converting an object to a series of bytes. You can mimic cloning by serialising and deserialising an object, however.
Sumit Suresh Rao
Greenhorn

Joined: Feb 16, 2009
Posts: 13
they are as different as Chalk and Cheese.

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cloning and Serialization ?