About author  I am Java/oracle professional.Working on Java/J2EE technologies and i.e Java,J2ee,Oracle ADF,hibernate,J2ee,PL/sql,Apps for 4+ years.I am passionate about learning new technologies.I am sharing my knowledge. Give your views and suggestion on vinay@techartifact.com http://www.linkedin.com/in/vinaykumar2 Read more from this author


Marker interface is a interface which don’t have any mehtod.It is used to tag the implementing class based on their purpose.Marker interface is a Java interface which doesn’t actually define any fields. It is just used to “mark” Java classes which support a certain capability –the class marks itself as implementing the interface. For example, the java.lang.Cloneable interface.
In java language programming, interfaces with no methods are known as marker interfaces or tagged interface.Marker Interfaces are implemented by the classes or their super classes in order to add some functionality.Marker interfaces are understood by the JVM. The JVM takes care of how to deal with a class that implements that marker interface

Why we use marker interface.
The marker interfaces are used to provide certain functionality to classes you code. Take for instance the Cloneable interface. This interface is implemented by the JVM itself and allows copies of objects to be created without the developer having to write code for this purpose. User written marker interfaces can also be used for inheritance purposes.Marker Interfaces are used to mark the capability of a class as implementing a specific interface at run-time.

Example of marker Interface.

java,lang.Cloneable
java,io.Serializable
java.util.EventListener

pimp it

10 Responses to Marker interface in java


  1. Java trainingNo Gravatar
    Aug 20, 2009

    Yes; and you can actually do the same with annotations as well now (to emulate interfaces). Not sure what the advantageous would be though…

    Example (in Dutch though):

    http://www.jtraining.com/blogs/annotations-nu-ook-voor-jou.html


  2. GaridanNo Gravatar
    Aug 20, 2009

    Now you should use annotations. Interfaces serve a different purpose, and nowadays should not be without methods. You can check implemented annotations at runtime too, see for example http://bill.burkecentral.com/2008/01/14/scanning-java-annotations-at-runtime/


  3. salvin francisNo Gravatar
    Sep 04, 2009

    Hi,
    What is the difference between an empty interface and an empty abstract class ?

    (Other than multiple inheritance)


  4. GobiNo Gravatar
    Sep 07, 2009

    Hi,
    Appreciate your efforts in putting this. It would be better to understand if you would have given some more example :-) .

    Just my thoughts…


  5. arun mehtaNo Gravatar
    Sep 06, 2010

    Yes; and you can actually do the same with annotations as well now (to emulate interfaces). Not sure what the advantageous would be though…


  6. arun mehtaNo Gravatar
    Sep 06, 2010

    Now you should use annotations. Interfaces serve a different purpose, and nowadays should not be without methods. You can check implemented annotations at runtime too,


  7. arun mehtaNo Gravatar
    Sep 06, 2010

    # salvin francisNo Gravatar – 09/4/2009 at 6:23 am

    Hi,
    What is the difference between an empty interface and an empty abstract class ?


  8. VamshiNo Gravatar
    Sep 09, 2011

    Hi all. Recently I am hearing a news that, Runnable, Comparable interfaces are also the marker interfaces. And they are saying that interfaces which have methods which give different behavior are marker interfaces. Please clear my confusion with examples if u can

Trackbacks/Pingbacks

  1. PimpThisBlog.com
  2. Exceptions

Leave a Reply