Thursday, 23 July 2015

Serialization in java

public interface Externalizable
    extends Serializable
{

    public abstract void writeExternal(ObjectOutput objectoutput)
        throws IOException;

    public abstract void readExternal(ObjectInput objectinput)
        throws IOException, ClassNotFoundException;
}


How many methods in the Externalizable interface?
There are two methods in the Externalizable interface. You have to implement these two methods in order to make your class externalizable. These two methods are readExternal() and writeExternal().


What is the difference between Serializable and Externalizable interface?
When you use Serializable interface, your class is serialized automatically by default. But you can override writeObject() and readObject() two methods to control more complex object serailization process. When you use Externalizable interface, you have a complete control over your class's serialization process.


What is a transient variable?
A transient variable is a variable that may not be serialized. If you don't want some field not to be serialized, you can mark that field transient or static.

No comments:

Post a Comment