• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Cloning and Serialization ?  RSS feed

 
Ranch Hand
Posts: 391
1
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.......
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Marshal
Posts: 60157
188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!