This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Serializing more than one value manually Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Serializing more than one value manually" Watch "Serializing more than one value manually" New topic
Author

Serializing more than one value manually

Catherine Zhu
Greenhorn

Joined: Aug 17, 2007
Posts: 2
Hi,

My question is, how do you serialize more than one int that cannot be serialized automatically. i.e. two transient int variables. And how do you tell them apart when you deserialize the object?

Next question is... do we need to know this for the exam? Well actually I would like to know anyway.

Thanks.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

"Cat,"

Please check your private messages by clicking on the "My Profile" link near the top of the page. Thanks!


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
Howdy ranchers,

and thank you, Cat, for changing your display name.

Welcome to the ranch!



To your question:
You have to write the two ints seperately. And read it seperately.
When you make the private void writeObject(ObjectOutputStream os) - method and the complementary readObject method, you have to be sure to do this in the right sequence.

Here is an example where I mixed it up (bold):

output:
[Bird with 2 legs and 2 wings, Fly with 6 legs and 2 wings]
null
[Bird with 2 legs and 2 wings, Fly with 2 legs and 6 wings]




Hope that helped.

Yours,
Bu.


all events occur in real time
Catherine Zhu
Greenhorn

Joined: Aug 17, 2007
Posts: 2
Thank you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Serializing more than one value manually