What is Difference between Serializable and Externalizable in Java serialization?



What is Difference between Serializable and Externalizable in Java serialization?..

Answer / javamasque

Serializable: It is marker interface, it has no method to override in implemented class. It enables the object to be serialized. If any object is tried to serialize without implementing Serializable interface, then JVM throws NotSerializableException. It uses JVM’s default serializing mechanism. There is no control by the program over serialization.

Advantages (Serializable implemented object)
1. JVM takes responsibility to store the state of object.
2. No overhead of method implementation for logic to write or read object state, to or from stream.
3. It is recommended to use as suitable as possible.
4. No default constructor is required.

Disadvantages
1. No control over object serialization.
2. We need to manually take care of static or transient state of objects
3. We have to implement serializable interface in all of its super class (if any) that we need to serialize.

Externalizable: It is not as serializable interface. The interface has two methods to implement for logic to write (writeExternal()) or read (readExternal()) object sate or behavior, to or from stream.

Advantages (Externalizable implemented object)
1. We have full control over content of object stream.
2. There is no special attention we need to provide for static or transient properties of an object.
3. No need to implement enternalizable interface to all of its super class (if any) that we need to serialize.

Disadvantages
1. It should not use as there is really need of it.
2. Takes overhead of writing logic to save state of an object.
3. Default constructor is required.

Is This Answer Correct ?    7 Yes 0 No

Post New Answer

More Core Java Interview Questions

What are generic methods?

0 Answers  


can we have function for truncating the sign as like abs in oracle.

1 Answers  


Why java strings are immutable in nature?

0 Answers  


What is the difference between the file and randomaccessfile classes?

0 Answers  


what is the purpose of method overriding in java where v r completely re-defining a inherited method instead y can't v create a new method and define.If the question is very silly plz excuse me and do reply.Thank U!

7 Answers   emc2, Kumaran Systems,


How many types of variables are there?

0 Answers  


How many types of gc are there in java?

0 Answers  


What is null statement?

0 Answers  


What is jit compiler ?

0 Answers  


In the below example, what will be the output?

0 Answers  


How do you add an element to a hashset in java?

0 Answers  


Does string is thread-safe in java?

0 Answers  


Categories