How does Serializable interface work

Posted on 2010-03-31
Medium Priority
Last Modified: 2012-05-09
Serializable interface is a marker interface. A marker interface has no methods in it. They mark the class by identifying the java type that confirms to the interface.
My question is just by implementing a class as serializable how is a class getting serialized without any serializable method being executed.
Question by:prsubject
  • 2
LVL 20

Assisted Solution

Venabili earned 248 total points
ID: 29260860
It just marks the class as Serializable in the JVM. After this when ObjectOutputStream needs to serialize, it does check if the object is from the type.

Think of this like locked features - when you implement the interface, you just unlock them.
LVL 92

Accepted Solution

objects earned 252 total points
ID: 29267797
how it all works is documented here


Expert Comment

ID: 29319933
One question to Venabili,

You told "Think of this like locked features - when you implement the interface,  you just unlock them."

But if you implement the same functionality which is present in ObjectOutputStream in one of your own class, and then use that class to serialize an Object (also you do not check in your implemented class whether the object to be serialized implements Serializable), will the object be not Serialized ??
LVL 20

Expert Comment

ID: 29623495
We are talking about how the interface works, not when an object is considered serializable :)

As far as the interface is concerned, I still call it unlocking of features. I am not saying that it is the only way to unlock them but this is the way to unlock it for the default implementation.

What you want to do outside of the standard way is up to you. If you want to implement all the serializations from scratch, you are welcome to.

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question