HowToDoInJava

  • Python
  • Java
  • Spring Boot
  • Dark Mode
Home / Java / Serialization / Difference between Externalizable vs Serializable in Java

Difference between Externalizable vs Serializable in Java

Knowing the difference between Externalizable vs Serializable is important in two aspects, one – if could be asked as an interview question, two – you can use the knowledge to make better informed decision for performance improvement for applying serialization into your application.

1. Differences between Externalizable vs Serializable

Let’s list down the main differences between Externalizable and Serializable interfaces in java.

SerializableExternalizable
Serializable is a marker interface i.e. does not contain any method.Externalizable interface contains two methods writeExternal() and readExternal() which implementing classes MUST override.
Serializable interface pass the responsibility of serialization to JVM and it’s default algorithm.Externalizable provides control of serialization logic to programmer – to write custom logic.
Mostly, default serialization is easy to implement, but has higher performance cost.Serialization done using Externalizable, add more responsibility to programmer but often result in better performance.
It’s hard to analyze and modify class structure because any change may break the serialization.It’s more easy to analyze and modify class structure because of complete control over serialization logic.
Default serialization does not call any class constructor.A public no-arg constructor is required while using Externalizable interface.

Please note that Externalizable interface is child interface of Serializable i.e. Externalizable extends Serializable. So if any class implements Externalizable interface and override it’s writeExternal() and readExternal() methods then first preference is given to these methods over default serialization mechanism provided by JVM.

Read More : How to override default serialization mechanism in java

2. Read More about Externalizable and Serializable

  • More Efficient Serialization with Externalizable in Java
  • Java Serializable Interface Implementation Guide
  • How Deserialization Process Happen in Java?

Drop me your questions in comments section related to Externalizable and Serializable interfaces in Java.

Happy Learning !!

Was this post helpful?

Let us know if you liked the post. That’s the only way we can improve.

Share this:

  • Twitter
  • Facebook
  • LinkedIn
  • Reddit

About Lokesh Gupta

A family guy with fun loving nature. Love computers, programming and solving everyday problems. Find me on Facebook and Twitter.

Feedback, Discussion and Comments

  1. mohammad

    April 16, 2017

    if there are large no of member variables , which needs not to be serialized then is there any other way other thann making it transient.?

Comments are closed on this article!

Search Tutorials

Java Serialization Tutorial

  • Serialization – Serializable Interface
  • Serialization – SerialVersionUID
  • Serialization – Externalizable
  • Externalizable vs Serializable
  • Serialization – Java Object to XML
  • Serialization – Deserialization Process
  • Serialization – ReadObject and WriteObject
  • Serialization – Deep Cloning using In-memory Serialization

Java Tutorial

  • Java Introduction
  • Java Keywords
  • Java Flow Control
  • Java OOP
  • Java Inner Class
  • Java String
  • Java Enum
  • Java Collections
  • Java ArrayList
  • Java HashMap
  • Java Array
  • Java Sort
  • Java Clone
  • Java Date Time
  • Java Concurrency
  • Java Generics
  • Java Serialization
  • Java Input Output
  • Java New I/O
  • Java Exceptions
  • Java Annotations
  • Java Reflection
  • Java Garbage collection
  • Java JDBC
  • Java Security
  • Java Regex
  • Java Servlets
  • Java XML
  • Java Puzzles
  • Java Examples
  • Java Libraries
  • Java Resources
  • Java 14
  • Java 12
  • Java 11
  • Java 10
  • Java 9
  • Java 8
  • Java 7

Meta Links

  • About Me
  • Contact Us
  • Privacy policy
  • Advertise
  • Guest and Sponsored Posts

Recommended Reading

  • 10 Life Lessons
  • Secure Hash Algorithms
  • How Web Servers work?
  • How Java I/O Works Internally?
  • Best Way to Learn Java
  • Java Best Practices Guide
  • Microservices Tutorial
  • REST API Tutorial
  • How to Start New Blog

Copyright © 2020 · HowToDoInjava.com · All Rights Reserved. | Sitemap

  • Java 15 New Features
  • Sealed Classes and Interfaces
  • EdDSA (Ed25519 / Ed448)