aspose file tools*
The moose likes Java in General and the fly likes Why Serializable doesnot have any method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Why Serializable doesnot have any method" Watch "Why Serializable doesnot have any method" New topic
Author

Why Serializable doesnot have any method

chets patel
Ranch Hand

Joined: Apr 27, 2010
Posts: 77

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

Joined: Aug 16, 2005
Posts: 14352
    
  22

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 8 API documentation
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39884
    
  28
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: 19762
    
  20

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

Joined: Sep 08, 2010
Posts: 97

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

Joined: Oct 27, 2005
Posts: 19762
    
  20

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Why Serializable doesnot have any method