
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
Difference between Serialization and Externalization in Java
Serialization and externalization both are the processes of converting an object to stream byte and storing byte stream in database or memory. The class which implements java.io.Serializable interface can be serialized. On the other hand, externalization used for custom serialization based on the requirement in the application. Externalization extends java.io.Serializable.
Sr. No. | Key | Serialization | Externalization |
---|---|---|---|
1 | Interface | Serialization is a marker interface | Externalization contains two methods readExternal and writeExternal. |
2 | Implementation logic | The class which is implementing this interface gives the responsibility to JVM for serializing or persist java object. JVM use readObject and writeObject for serialization | Externalization provides implementation logic control to the application by overriding readExternal and writeExternal methods. |
3 | Way to ignore variables | In serialization, JVM ignores transient variable during serialization and deserialization of java object | Programmer can write their own logic to ignore some of the variables during externalization of java object |
4 | Performance | In serializable interface uses reflection which causes relatively slow performance. | Externalizable gives full control over the implementation approach. |
5 | Object serialization with inheritance | 1. If the superclass is not serializable then the subclass still can be serialized. 2. If a subclass is not serialized but superclass is automatically serializable | We can apply this to externalizable as well. |
Example of Externalizable
class ExternalizableExample implements Externalizable { Integer id; @Override public void writeExternal(ObjectOutput out) throws IOException { out.writeInt( id ); } @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { this.id = in.readInt(); } }
Example of Serializable
class SerializableExample implements Serializable { private static final long serialVersionUID = 5081877L; String name; }
- Related Articles
- What is the difference between Serialization and Deserialization in Java?
- Difference between readObject and readResolve method in serialization
- What is Serialization in Java?
- Object Graph in Java Serialization
- Object Serialization with inheritance in Java
- Object Serialization with Inheritance in Java Programming
- How transient works with final in Java serialization?
- Serialization and Deserialization in C#
- Difference between Java and JavaScript.
- Difference between Go and Java.
- Difference Between C++ and Java
- Difference between Groovy and Java
- Difference between constructor and method in Java
- Difference between Object and Class in Java
- Difference between HashMap and HashTable in Java.

Advertisements