Wednesday 29 February 2012

Serialization

1) What is Serialization?In order to transfer object over network or store the object in file system it must be converted in to byte stream. Serialization converts object to byte steram.To Serialize an object our class must implement Serializable interface.Serializable is a Marker interface i.e. has no methods to override. It must be implemented to tell the JVM that object of this class must be converted to byte stream

2) How to customize serialization
To customize serialization we can implement Externalizable interface and override readExternal() and writeExternal() methods

3) Can object having references to no serialized objects be serialized
No.In this case NotSerializableException will be thrown at runtime.

4)Whether static variable are also serialized
No. Static variables are not serialized
5)What is transient variable
Transient variables are skipped from serialization. Transient variables take default value after deserialization

4) If subclass is serializable but super class is not serializable what will happen?
In this case during deserialization super class constructor runs and the inherited variables from super class gets initialized with default values

5) If we want to serialize array or collection whether all members needs to be serialized?
Yes

No comments:

Post a Comment