This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Java in General and the fly likes marker interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "marker interface" Watch "marker interface" New topic

marker interface

Shrawan Bhageria
Ranch Hand

Joined: Jun 20, 2005
Posts: 52
hi all

what is marker interface n why it is used in java ? could any body explain it wth some example ?
Though there are no methods in marker interfaces like , how this the serialization will be done.

pl. help

SCBCD 1.3(preparing)
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42958
A marker interface is used to indicate to the JVM that a class that implements it has a particular property. With Serializable, it indicates that the class *CAN* be serialized. How serialization then is accomplished is described in the javadocs for Serializable.
There is at least one other marker interface in the JDK, but I can't think of which one it was right now.
Shrawan Bhageria
Ranch Hand

Joined: Jun 20, 2005
Posts: 52
but i can't understand what u say
pl. can u explain it wth some example

Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
A marker interface is used to inadvertantly introduce a design flaw.
A marker interface is typically better described as "metadata" with some contractual properties associated with it.
For example, you could eliminate the marker interface and introduce a Serializable annotation with associated contract (i.e. in the javadoc), since it is annotations that are the correct tool for metadata, and prior to 1.5, mere javadoc; it has never been interfaces, despite the flaws that are evident in the core API.

Tony Morris
Java Q&A (FAQ, Trivia)
I agree. Here's the link:
subject: marker interface
It's not a secret anymore!