Difference between Serialization and Externalization in Java

Difference between Serialization and Externalization

Difference between Serialization and Externalization

We have already seen complete tutorial about Serialization in java. To know more about serialization, visit the links which is given below. During interviews, many people come across questions from difference between Serialization and Externalization. In this post we will see the difference between these two.

To Know More: Java Serialization – Complete Tutorial with Example for Beginners

To Know More: Java Serialization with Inheritance

To Know More: Transient Variable vs Static Variable

To Know More: What is serialVersionUID in Serialization with Example

To Know More: Externalization in Java

Difference between Serialization and Externalization in Java

  • In Serialization, entire object will be serialized. In Externalization, based on the requirement either full object or part of the object will be serialized.
  • In Serialization, JVM will have complete control in serializing the object. In Externalization, programmer will have complete control in serializing the object.
  • Serializable is a marker interface so it doesn’t contain any methods. Externalizable contain two methods i.e writeExternal and readExternal.
  • If we implement Serializable interface, then during deserialization new object will not be created by executing any constructor. But if we implement Externalizable interface, then during deserialization new object will be created by executing No-arg Constructor.
  • In Serializable interface, Serialization won’t happen if we declare a variable with transient keyword. So transient keyword play a major role in Serializable interface. But in Externalizable interface developers will have the complete control, so even if he declared variable with transient keyword and write that variable value in writeExternal method, then that variable state also will be serialized. So transient keyword doesn’t play any role in Externalizable interface.

If you have any question on difference between serialization and externalization tutorial, please comment your queries in the comment box. If you like this tutorial, please share it with your friends by clicking on the share button. To get latest updates from our site, please subscribe to the page.