• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

rules for serialization and a question

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 58
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 144
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?!
 
It is difficult to free fools from the chains they revere - Voltaire. tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic