jQuery in Action, 2nd edition*
The moose likes Beginning Java and the fly likes serialization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "serialization" Watch "serialization" New topic
Author

serialization

AJ sisodia
Greenhorn

Joined: Jan 19, 2005
Posts: 16
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

Joined: Apr 14, 2004
Posts: 10336


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 ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41621
    
  55
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.


Ping & DNS - my free Android networking tools app
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
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.


Tony Morris
Java Q&A (FAQ, Trivia)
Sathya Srinivasan
Ranch Hand

Joined: Jan 29, 2002
Posts: 379
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.


Cheers, Sathya Srinivasan - SCJP 1.2, SCWCD 1.2, SCMAD 1.0
Co-Author of Whizlabs SCMAD Certification Exam Simulator and SCMAD Exam Guide Book
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: serialization