• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Denny's DVD Serialize or standard file

 
Javier Corral
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm confused about saving a DVD in Denny's DVD project. In page 143 method retrieveDvd uses a standard file whereas in page 167 method retrieveDVD uses serialization. Last paragraph says that serialization methos is used as pedagogically but file DVD.java implements Serializable and the method readObject.

Does Denny's DVD project use Serialization for DVD class in some part of the code?

Thank you.
 
Ken Boyd
Ranch Hand
Posts: 329
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you can post the code I might able to help you. Otherwise I will post after reaching home..

Ken
[ June 29, 2007: Message edited by: Ken Boyd ]
 
Javier Corral
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the code I don't understand. Why is implemented readObject if DvdDatabase uses RandomAccessFile for reading and writing?.



public class DVD implements Serializable {
...
...
/**
* When de-serializing this object, make sure we have a logger.
* Note that the method signature must match <b>exactly</b>.
*/
private void readObject(java.io.ObjectInputStream in)
throws IOException, ClassNotFoundException {
log = Logger.getLogger("sampleproject.db"); // Log output
in.defaultReadObject(); // call the standard deserializer
}
}
 
Gabriel Vargas
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Javier,

If my memory is not bad, in this section Andrew talk about Serializable and Externalizable and what is their purposes. If you look Serializable API (5.0) you can find next paragraphs:


Classes that require special handling during the serialization and deserialization process must implement special methods with these exact signatures:

private void writeObject(java.io.ObjectOutputStream out)
throws IOException
private void readObject(java.io.ObjectInputStream in)
throws IOException, ClassNotFoundException;


And in a follow paragraph say:


The readObject method is responsible for reading from the stream and restoring the classes fields. It may call in.defaultReadObject to invoke the default mechanism for restoring the object's non-static and non-transient fields.


Andrew is explain how Serialization process happen and only override readObject/writeObject for add a logger line as this comment tell us:


When de-serializing this object, make sure we have a logger.


I hope it helps you.
 
Ken Boyd
Ranch Hand
Posts: 329
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Javier Corral:
This is the code I don't understand. Why is implemented readObject if DvdDatabase uses RandomAccessFile for reading and writing?.



public class DVD implements Serializable {
...
...
/**
* When de-serializing this object, make sure we have a logger.
* Note that the method signature must match <b>exactly</b>.
*/
private void readObject(java.io.ObjectInputStream in)
throws IOException, ClassNotFoundException {
log = Logger.getLogger("sampleproject.db"); // Log output
in.defaultReadObject(); // call the standard deserializer
}
}


quote from book


Caution: The code shown in these listing is not contained in the actual project since Denny's DVDs relies on the JVM and the default serialization mechanism. The code is used as a pedagogical device to illustrate how to explicitly serialize an object.



if do the above then yes DVD impelments serialization


Ken
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic