File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

rules for serialization and a question

 
mark juszczec
Ranch Hand
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 58
Eclipse IDE Java Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 144
Java Linux Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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?!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic