Marker interface in java

By Vinay | August 20, 2009 | 7,541 views
Category .NET, Common, Java, open source


About author  I am Java/oracle professional.Working on Java/J2EE technologies and i.e Oracle ADF,Spring,hibernate,J2ee,PL/sql,Apps for 2+ years.I am passionate about learning new technologies.I am sharing my knowledge. Give your views and suggestion. 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

Read more post on Java marker interface in java purpose of marker interface what is marker interface 

5 comments | Add One

Comments

  1. Java trainingNo Gravatar - 08/20/2009 at 7:07 am

    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 - 08/20/2009 at 2:25 pm

    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 - 09/4/2009 at 6:23 am

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

    (Other than multiple inheritance)



  4. GobiNo Gravatar - 09/7/2009 at 6:47 am

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

    Just my thoughts…



Trackbacks

  1. PimpThisBlog.com

Leave a Comment

Name:

E-Mail :

Website :

Comments :