| Author |
Why Serializable doesnot have any method
|
chets patel
Ranch Hand
Joined: Apr 27, 2010
Posts: 69
|
|
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
Bartender
Joined: Aug 16, 2005
Posts: 12921
|
|
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:
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32675
|
|
|
The JVM looks at any object it is trying to serialise, and checks it is marked as "Serializable".
|
 |
Gaurav Sagar
Ranch Hand
Joined: Sep 08, 2010
Posts: 97
|
|
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
Joined: Oct 27, 2005
Posts: 19216
|
|
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
Joined: Sep 08, 2010
Posts: 97
|
|
Rob Prime wrote:
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
Joined: Oct 27, 2005
Posts: 19216
|
|
|
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.
|
 |
 |
|
|
subject: Why Serializable doesnot have any method
|
|
|