It was marked duplicate and i am expanding my question.
My question is how JDK internally serializing objects. How ObjectxxxStreams class serializing when the class implements that interface.?
I was looking into the serialization topic and deeply dived into the JDK Source code.
This was the source code of serialization Interface in JDK.
package java.io;
public interface Serializable {
}
There is nothing in this interface. What is the use of implementing this interface. I know that, to serialize a object we should implement this. I know what serialization is and how to work with that. But how serialization happens internally using ObjectInputStream
and ObjectOutputStream
. These classes are how related to serialization. Alternatively let us keep that those two classes are doing their duty. All my question is why we need to implement this empty interface to serialize and deserialize objects and how it works internally? Please explain in detail about this.
why we need to implement this empty interface ??
Its a design pattern
The marker interface pattern is a design pattern in computer science, used with languages that provide run-time type information about objects. It provides a means to associate metadata with a class where the language does not have explicit support for such metadata.
Serializable is marker interface
java.io.Serializable marker interface. It doesnot has any members defined it it. When a java class is to be serialized, you should intimate the java compiler in some way that there is a possibility of serializing this java class. In this scenario, marker interfaces are used.
Refer javadoc and Requirement of the serializable interface
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With