Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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?!
 
reply
    Bookmark Topic Watch Topic
  • New Topic