This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Serialization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Serialization" Watch "Serialization" New topic
Author

Serialization

Neelesh Bodas
Ranch Hand

Joined: Jul 20, 2006
Posts: 107
This question is about the methods defaultWriteObject() and defaultReadObject().
Java allows me to define my own version of writeObject() in the class which implements Runnable :


My question is : how does defaultWriteObject get to know about the "this" reference while getting executed? (It must be knowing about it since it does the necessary serialization). We never pass "this" reference to it!!

[ July 20, 2006: Message edited by: Neelesh Bodas ]
[ July 20, 2006: Message edited by: Neelesh Bodas ]
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 20166
    
  46

My question is : how does defaultWriteObject get to know about the "this" reference while getting executed? (It must be knowing about it since it does the necessary serialization). We never pass "this" reference to it!!


The ObjectOutputStream already knows which object (and part of) is in progress. It is the ObjectOutputStream that called your WriteObject() method, passing a reference to itself. So, basically, calling defaultWriteObject() just means to write the current piece in progress to the stream.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Serialization
 
jQuery in Action, 3rd edition