File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Java » Java in General
Bookmark "marker interface" Watch "marker interface" New topic
Author

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 java.io.Serializable , how this the serialization will be done.

pl. help
thanks
shrawan

SCJP 1.4,SCWCD 1.4,MCP
SCBCD 1.3(preparing)
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42596
    
  65
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.


Ping & DNS - my free Android networking tools app
Shrawan Bhageria
Ranch Hand

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

regard
shrawan
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 java.io.Serializable 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)
 
Don't get me started about those stupid light bulbs.
 
subject: marker interface