• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why Serializable doesnot have any method

 
chets patel
Ranch Hand
Posts: 77
Eclipse IDE Redhat Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
If Serializable interface does not have any method, then how it serve the purpose of serialization.
What happens internally.
I am confused.
Please let me know.

Thanks in advance.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15219
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Serializable is a marker interface. You use it to indicate that a class should be serializable. Other code can check if an object is serializable using the instanceof operator, for example:
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JVM looks at any object it is trying to serialise, and checks it is marked as "Serializable".
 
Gaurav Sagar
Ranch Hand
Posts: 97
Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Serializable is a markup interface just like many other as SingleThreadModel, EventListener, Cloneable, RandomAccess, etc. These interfaces are just used to tag the class having certain special characterstic which is recognized by the JVM at runtime, for eg.:-
Only the classes implementing the Serializable have the capability to save their state. Here the marker Serializable on the class suggests the JVM at runtime that its state could be saved.
This is the reason these are also known as TAG intefaces. Java gives the facility to create empty interfaces.

Regards,
Gaurav
 
Rob Spoor
Sheriff
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gaurav Sagar wrote:many other as SingleThreadModel, EventListener, Cloneable, RandomAccess, etc.

I think EventListener does not fit in that list. It's not just a marker interface, it's the root of the entire event listener interface hierarchy.
 
Gaurav Sagar
Ranch Hand
Posts: 97
Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:
Gaurav Sagar wrote:many other as SingleThreadModel, EventListener, Cloneable, RandomAccess, etc.

I think EventListener does not fit in that list. It's not just a marker interface, it's the root of the entire event listener interface hierarchy.


I said so since java.util.EventListener is just another empty interface, so it ought to be a marker interface.
 
Rob Spoor
Sheriff
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Empty interface and marker interface are not necessarily synonyms. A marker interface is empty, but an empty interface can also have other purposes than just type checking, which is essentially what marker interfaces are for. Cloneable, Serializable, RandomAccess, SingleThreadModel - all just perfect examples.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic