Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

serialization

 
AJ sisodia
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why do we serialize an object?I know we can send data without using the concept of serialization?then why to serialize objects?
Please answer
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I know we can send data without using the concept of serialization

We can send data, but we can't transfer an object without Serialization.
[ February 16, 2006: Message edited by: Paul Sturrock ]
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm going to nitpick about what Paul said - it depends on your definition of "object equality" and "serialization".

If you're talking about the actual object instance (which is identical in the sense of "=="), then Paul is exactly right: you need to use Java object serialization, and only a Java client will be able to make sense out of it.

If you're talking about an object that is identical in the sense of the "equals" method, you can use other serialization methods (e.g. java.beans.XMLEncoder or the serialization used in Web Services) to get an object which acts the same way the original would have.
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ulf Dittmer:
I'm going to nitpick about what Paul said - it depends on your definition of "object equality" and "serialization".

If you're talking about the actual object instance (which is identical in the sense of "=="), then Paul is exactly right: you need to use Java object serialization, and only a Java client will be able to make sense out of it.

If you're talking about an object that is identical in the sense of the "equals" method, you can use other serialization methods (e.g. java.beans.XMLEncoder or the serialization used in Web Services) to get an object which acts the same way the original would have.


I can't make any sense of this reasoning, but I strongly suspect that it is inaccurate. You can certainly use any kind of serialization to serialize and deserialize to the same instance - even standard Java serialization, which is extremely inflexible. Likewise, you can do the same for any object such that the equals method (ick) evaluates to true.

http://contractualj.com/api/net/tmorris/serialization/SerializationScheme.html can also do permit all of that and more.
 
Sathya Srinivasan
Ranch Hand
Posts: 379
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Serialization is a mechanism where a Java object can be preserved across a network. Essentially, it is an object encoded in a specific format such that it can be 'recreated' on a different machine with the same data.

Originally posted by Ulf Dittmer:

If you're talking about the actual object instance (which is identical in the sense of "=="), then Paul is exactly right: you need to use Java object serialization, and only a Java client will be able to make sense out of it.


Not true. By definition, an object is 'recreated'. This means that the new object will have a totally different memory address even if it is deserialized in the same VM. Thus, the '==' operator will always return false when comparing an object and its serialized/deserialized version and the 'equals' method will always return true.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic