• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Serialization in java

 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hai im having some doubts in this program:



1)why we have used writeInt in line three?what it does and what is the use of this in this program?

2)does the methods writeObject(ObjectOutputStream os) and readObject(ObjectInputStream is) is the altenative of


and


please explain me in detail thanks in advance
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

kiruthigha rajan wrote:

1)why we have used writeInt in line three?what it does and what is the use of this in this program?




First, we can only speculate -- as we don't have any context on what is the implementation for.

It looks like programmer don't want to serialize the Collar object -- the comment states that it isn't possible to serialize it.... However, the Dog object needs it. And it looks like it is possible to simply get another Collar upon deserialization -- provided the collar size is correct. So, the programmer sent the dog collar size as part of the serialized stream.

Henry
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

kiruthigha rajan wrote:
2)does the methods writeObject(ObjectOutputStream os) and readObject(ObjectInputStream is) is the altenative of


and



No. This is not an alternative. The first snippet is a modification on how the object should be serialized (specifically the components related to the Dog class only). This set of snippets is the actual serialization and deserialization of the object. This set of code will call the other set of code when it is time to serialize the Dog class component of the Dog object.

Henry

 
kiruthigha rajan
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is the difference between writeObject(),readObject() and defaultWriteObject(),defaultReadObject()?
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sun has a decent article that describes everything.

http://java.sun.com/developer/technicalArticles/Programming/serialization/

It's certainly better than learning it piecemeal via forum exchanges.

Henry
 
reply
    Bookmark Topic Watch Topic
  • New Topic