my dog learned polymorphism*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes rules for serialization and a question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "rules for serialization and a question" Watch "rules for serialization and a question" New topic
Author

rules for serialization and a question

mark juszczec
Ranch Hand

Joined: Aug 20, 2011
Posts: 35
First, the question - is Externalizable covered on the SCJP exam?

I've tried to come up with a list of rules for Serializing classes. Are they accurate? Is anything missing?

An object is serializable if and only if its class or its superclass implements the Serializable or Externalizable interface.

A subclass is serializable even if its superclass is not:
The class MUST impl Serializable.
First superclass in the hierarchy of the serializable class that does not implements Serializable interface, MUST have a no-arg constructor.
If this is violated, readObject() will produce a java.io.InvalidClassException in runtime.

The no-arg contructor of every non-serializable superclass will run when an object is deserialized.

The deserialized object’s constructor does not run when it is deserialized.

The class must be visible at the point of serialization.

All primitive types are serializable.

Transient fields (marked by transient modifier) are NOT serialized.

A Serializable class must mark transient fields of classes that do not support serialization (e.g., a file stream).

Static fields (marked by static modifier) are not serialized.

If member variables of a serializable object reference a non-serializable object, the code will compile but a RumtimeException will be thrown.

Mark
Suhrid Karthik
Ranch Hand

Joined: Aug 31, 2008
Posts: 58

Serialization is not on the exam's objectives as of now. However, I suppose it was removed somewhat recently, so a lot of the mock exams do have serialization based questions. I guess, it's good to be familiar with the topic, but you wouldn't have to delve into it for the sake of the exam.
Hama Kamal
Ranch Hand

Joined: May 29, 2011
Posts: 144


First superclass in the hierarchy of the serializable class that does not implements Serializable interface, MUST have a no-arg constructor.
If this is violated, readObject() will produce a java.io.InvalidClassException in runtime.



can you give an example for this one?!


``Worry does not empty tomorrow of its sorrow; it empties today of its strength.''
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: rules for serialization and a question
 
Similar Threads
Serialize GUI (Swing)
Questions on serializable and deserializable understanding
serializable
Serializable vs Externalizable
doubt regarding serialization in java