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

Vinay

Sr Java Consultant-working on Java/J2EE/Oracle ADF/Hibernate/Webcenter/Portal for Around 7 years. I'm an active member of hte OTN JDeveloper forum .Passionate about learning new technologies.I am here to share my knowledge. Give your views and suggestion on [email protected] .

More Posts - Website

Follow Me:
TwitterLinkedInGoogle PlusYouTube

  • Pingback: PimpThisBlog.com

  • http://www.jtraining.com Java training

    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

  • Garidan

    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/

  • http://www.salvin.in salvin francis

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

    (Other than multiple inheritance)

  • Gobi

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

    Just my thoughts…

  • http://www.rediff.com arun mehta

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

  • http://www.rediff.com arun mehta

    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,

  • http://www.rediff.com arun mehta

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

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

  • Pingback: Exceptions

  • Vamshi

    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

    • http://www.facebook.com/profile.php?id=100003407204034 Seneque

      Java is suffering a death-by-a-thousand cuts by bad Java derpeoelvs more than anything else, and Eclipse and similar tools provide a catalyst for this, though they can’t be held entirely responsible.Projects such as Maven, Google App Engine, Spring, JPA and the Servlet standards seem unable to use actual Java language constructs. Their design choices introduce run-time errors which should actually be compile-time errors and create a thicket of XML which is impossible to navigate or debug, all to essentially manage jars on your classpath something which is already quite adequately defined by the java specification! Subsequently a million projects are born to attempt to overcome the new modes of failure which are possible by introducing bloated tools and plugins to handle the unnecessary complexity.Actually working on your code becomes a secondary activity, compared to dealing with badly documented conventions which weren’t needed in the first place.When two or more of these projects are simultaneously trying to manage your classpath, you’d better look out. It’s almost as if there were contributions in these community processes which were DESIGNED to trigger a Java death spiral.If Oracle were a grown up company, rather than a school bully, they would be setting a new direction, away from Sun’s laissez faire community process, and increasing the value of Java a thousandfold, by implementing and forcing through standards to meet the modern needs of an enterprise (dependency management, persistence, web service) which actually demonstrate the use of the Java language!The best reference example for me is Guice, which uses Java code for dependency management instead of the bizarre XML and other serialised formats fostered by other projects formats which simply help the authors show off that they went to Parsers 101, and along the way destroy the value inherent in the design choices of the Java language.

  • HeeptEstaftaf

    Thanks for the info.Really like your blog

  • http://www.javaexperience.com/ Java Experience

    Marker interfaces in Java are used for marking a specific behavior and we can only simulate the behavior by writing custom interfaces without any methods and having implementing them by other classes.