Java Marker Interface

Marker interface is used as a tag to inform a message to the java compiler so that it can add special behaviour to the class implementing it. Java marker interface has no members in it.

Lets take the marker interface. It doesnot has any members defined it it. When a java class is to be serialized, you should intimate the java compiler in some way that there is a possibility of serializing this java class. In this scenario, marker interfaces are used. The java class which may be serialized has to implement the marker interface. In such way, we are intimating the java compiler.

From java 1.5, the need for marker interface is eliminated by the introduction of the java annotation feature. So, it is wise to use java annotations than the marker interface. It has more feature and advantages than the java marker interface.

Is Runnable a marker interface?

First point, there is no reference or definition about marker interface from Java specification/api. This is yet another inconclusive debate. ‘Marker Interface’ is a term coined by (book / web) authors. Since we don’t have Java’s definition it is left to us to arrive at a decent definition. This is one popular question asked in java interview. My answer to the interviewer, there are better questions ask than this to ask.

“Runnable is not a marker interface”, you might say ‘run’ is used to start a method and this is a special instruction to the JVM.  When you run a java class the java interpreter calls the ‘main’ method, because of this would you say every java class as “marker class”?

‘My’ definition for marker interface

“An interface is called a marker interface when it is provided as a handle by java interpreter to mark a class so that it can provide special behaviour to it at runtime and they do not have any method declarations”.

In the above definition “and they do not have any method declarations” is added because, till now all the marker interfaces provided by java do not have method declarations. I dont think, in future there will be any new marker interfaces added :-)

We cannot create marker interfaces, as you cannot instruct JVM to add special behavior to all classes implementing (directly) that special interface.

Java Marker Interface Examples

This Abstract and Interface tutorial was added on 29/05/2008.

Comments on "Java Marker Interface" Tutorial:

  1. […] for copy or to the least it should invoke the super.clone(). Also you have to implement Cloneable marker interface or else you will get CloneNotSupportedException. When you invoke the super.clone() then you are […]

  2. Ram says:

    Dear Joe
    I have been reading books and blogs related to this topic of marker interface but I find everyone of them convoluted and unclear on the exact purpose. several questions and concern arise based on the explanations. For example consider marker interface serializable. How does the compiler differentiate between the two classes since their is no members defined in serializable interface.

  3. Prasad says:

    Good explanation Joe !!
    @Ram : In case of a marker interface i guess there is a type check like :
    if(myRef instanceOf Serializable) {
    // do serialiazation stuff

    with which the compiler knows about the marker interfaces (and their special meaning). As of java 1.5 marker interfaces are obsolete and annotations should be used otherwise.
    Correct me if i am wrong.
    Good luck :)

  4. Alps says:

    Gud xplanation but have some queries.
    Wats the use of a Marker Interface.When shall we can use user defined interface as marker interface.

  5. praneeth says:

    how the compiler differentiate normal classes and classes implementing these marker interfaces even though the marker interface dont have any members

  6. Shital says:

    Nice Explaination……
    one query- Can you Provide Example for getting the concept clearly….??

  7. Kavitha says:

    Hi frnds give me a clear clarification regarding marker interfaces..
    why use them,wat is the need..?

  8. Jana says:

    Marker interface does n’t have any method declaration, It tells to the compiler “This class for that purpose”….
    ie. Cloneable, serializable, eventListener

  9. Ashish says:

    private class bean implements Serializable{
    int id;
    String name;
    public int getId() {
    return id;
    public void setId(int id) { = id;
    public String getName() {
    return name;
    public void setName(String name) { = name;


  10. Anonymous says:

    public class myBean implements Serializable{
    private int id;
    private String name;
    public int getId() {
    return id;
    public void setId(int id) { = id;
    public String getName() {
    return name;
    public void setName(String name) { = name;

  11. santosh says:

    I think compiler won’t recognize the interface is a marker interface or not,only JVM will recognize it.If we are using serialization concept to save state of a object without implementing that class to the Serializable interface then we will get a runtime exception saying NotSerializableException.So from my point of view compiler won’t know anything about whether a interface is marker or not,only JVM is internally designed in such a way to provide some new ability to the class which implementing the marker interface.
    Some examples of marker interfaces are :-
    1) Serializable
    2) Cloneable
    3) RandomAccess
    4) SingleThreadModel
    5) EventListner

  12. bharath says:

    please,i would like to know in a clarity about the “Marker Interface” with example.

  13. Anonymous says:

    I think the comment from :santosh (on October 5th, 2011 11:20 am), is correct.It should be providing a msg to JVM rather than compiler.

  14. Ankur says:

    Can you plz provide an example how we can use annotations in place of marker interfaces.

  15. RAJ says:

    you are told marker interfaces are not contain methods then externalizable class is containing the own methods but it is a extends of the serilazable . then im saying marker interfaces are may be contaning the methods or may not be containing methods


  16. muthu says:

    Hi Joe,

    I have been analyzing marker interface for more than one month .I found that they are two groups of people wrote solution

    Group I : Marker interface does not contain any methods.It is just for giving information to compiler that this class will do seralization/cloneable operation.

    Group II : Runnable is a marker interface.It has method of run().So,marker interface need not be empty methods.

    I found that there is no keyword used as like ‘marker’ in java api in Serializable/Cloneable as well as Runnable .

    So, Could you give your suggestion on this ?

  17. muthu says:

    Hi Joe,

    I have been analyzing marker interface for more than one month .I found that they are two groups of people wrote solution

    Group I : Marker interface does not contain any methods.It is just for giving information to compiler that this class will do seralization/cloneable operation.

    Group II : Runnable is a marker interface.It has method of run().So,marker interface need not be empty methods.

    I found that there is no keyword used as like ‘marker’ in *JAVA API DOC in Serializable/Cloneable as well as Runnable .

    So, Could you give your suggestion on this ?

  18. Brahmi says:

    Is Runnable is a marker interface or not?

  19. Brahmi says:

    Is Runnable is a marker interface or not?

    if yes why?

  20. Geetanjali says:

    I want Purpose of marker interface. I know What is marker Interface Can u tell me? ………

  21. kavitha says:

    Is there any other way to make Serializable other than implementing Serializable Interface.I had interview today morning they asked this question.Can any body pls help me.

  22. Joe says:


    you can use the Externalizable Interface. It has two methods, writeExternal(..) and readExternal(..). You should override these two methods and provide your implementation (protocol) for serialization.

  23. Anantha Prakash says:


    The main purpose to have marker interfaces is to create special types in those cases where the types themselves have no behavior particular to them.

    This will give birth to another question like
    If there is no behavior then why to have an interface?

    Because the implementor of the class might only need to flag that it belongs to that particular type and everything else is handled/done by some other unit – either internal to Java (as in the case of Java supplied standard marker interfaces) or an app specific external unit.

  24. pallav rajput says:

    as we know that marker interface doesn’t have any method. but the question is why to use marker interface like cloneable or Serializable type of interface. and how it works?? actually for an example using clone() method is not secure operation for jvm. so what marker interface does, it will give one mark or u can say one permission to jvm that plz grant this operation as a secure operation. and jvm permit this operation. so marker interface is used for marking the permission to any method.

  25. kavitha says:

    Thank you so much Joe for explaination of my query,It is really nice site for Java people.Thanks lot for your effort.

  26. suraj says:

    As far as I have researched,Marker Interface means an interface which can provide special behavior to its child object.
    The presence of Method is not really necessary,But the behavior is Important.

    Some people say interface w.o method is called marker interface.
    My question back to them is,if u define an interface w.o any method,will JVM treat it as marker.Certainly not..

  27. Joe says:


    “Runnable is not a marker inteface”.

    I have added my comment in detail at the end of the article.

    Thanks for stopping by and adding the comment.

  28. Daksh says:

    Good job done,

  29. Preethi says:

    joeeee, u are special, thanks….

  30. Sudeer Verma says:

    nice explanation of marker interface

  31. Krishna says:

    thanks for your stuff..

  32. Dhanesh says:

    Great captions for this topic. Crisp and fruitful stuff.


  33. Anonymous says:

    Good one Joe

  34. krishna says:

    Hi , pls tell me

    what is the best practices of collection frame work?

  35. Anonymous says:

    how jvm identify the class implements MarkerInterface or not?i mean based on serialversion uid or instanceof operator.

  36. Jai says:

    Sir please explain anonymous inner class.

  37. neha says:

    please define java for me

  38. naveen says:

    but camparable interface is marker interface and has compareto() method how?

  39. arivoli says:

    Good explanation Joe !!

  40. Anonymous says:

    excellent material guidance

  41. Praveen Rohal says:

    excellent work Joe…

  42. Deepthi says:

    There is absolutely nothing special about a marker interface — it’s just an interface with no methods. The only thing that makes them matter is that there’s code somewhere that checks “instanceof” against them; for example, the java.lang.Object version of clone() checks “this instanceof Cloneable” before it will actually do anything.

  43. venkata says:


    How JVM understand serilization?
    I mean how this is implemented in JVM, As this is market interface no method will there and its just sign to JVM saying that to serilize object.

    Could you please tell me how serilization is done in JVM and how it understands by sign or keyword.


  44. satyanand singh says:

    excellent answer—-well defined—-way of documentation from begin 2 end was serial and it was damn xcelnt

  45. Vitthal Shirke says:

    Good explanation.

  46. shilly says:

    what is the use of marker interface?

  47. sri says:

    How to write our marker interface? what kind of changes we need to do sothat the compiler will recognize it as marker interface?

  48. anji says:

    How exactly we can find it is a marker interface(except behavior thing ).How can identify JVM. All interfaces are Marker interfaces, which are not have behaviors.

  49. Anonymous says:

    give some more examples

  50. kamalakkannan says:

    purpose of msrkerInterface?
    purpose of null Interface?
    pls any one help me……….

  51. atul says:

    Awesome sir!!

  52. Subbhu Reddy says:

    This article is confusing and not correct what is said above. Compiler never determines whether the interface is a marker Vs. not marker instead this process is evaluated by JVM at runtime.

    I think, the author of this article is totally confused b/n compiler and interpreter (runtime JVM)and misleading people.

  53. Fareed says:

    Good Explanation for market interface .

    Thanks Q Very Much

  54. Fareed says:

    Opps its marker interface not a market interface

  55. Paras Jain says:

    Your explenation language is vere good,

    Keep It Up…

  56. Paras Jain says:

    Can we Override constructer ?

    If Yes then how ?

    If no then why ?

    I am waiting for your answer…

  57. Anonymous says:

    How can we write our Custom marker inteface

  58. Mamta says:

    Consider 2 students X,Y in a class. X stood first in class, Even-though both are in same class, having similar properties and behavior. one can differ the both based on the stuff. There is no use of marking a person as smart. But it adds a special property to the person. Like marker Interface, JVM creates some interfaces that make a difference to classes. It just do nothing but adds a special behaviour.

  59. Siddesh Sahu says:

    if you extends any marker interface than your interface also become marker interface it will acquire all the properties of marker interface because some where in jvm it uses instanceof property to check. but we are still not able to change the behavior of jre to create directly our own marker interface without extending any existing marker interface

  60. Mamta says:

    So, If a extend a marker interface then my interface is also a marker interface.
    Can I declare methods in that?
    (Marker interface should not have a single method)

  61. anjaneyelu says:

    yes !! I will agree with this A Marker interface may or may not contain methods for ex. The externalizable interface contain readInternal() and writeExternal() methods

  62. Anjaneyelu says:

    As my knowledge Concern a marker Interface may contain methods for ex. Java.Lang.Runnable, Java.Lang. Externalizable and some more…..

  63. Anjaneyelu says:

    As me Concern Runnable is a marker Interface why because if our java class is not implements to the Runnable Interface then the object will act as normal object. that means it contains all state and behaviour of the class. otherwise if our class is implements Runnable Interface then the Implemented class object will get special behaviour given by the JVM. That means it will act as a Thresd unlike Process

  64. Anjaneyelu says:

    As me concern an Interface called as a Marker Interface if and only if, the implemented class object will get special identity and behaviour at the time of runtime rather than normal behaviour.

    if our class implements marker Interface , the implemented class object will get Special Identity and behaviour given by the JVM. For Ex.
    A java class implemets Runnable Interface , then the Object will acts as a Thread
    A Java class that implements Serializable, then the implemented class object will get such a behaviour it can tranfer across the Network
    like this many more like
    Java.lang. Clonable

  65. manoj says:

    Hi joe,
    We can create marker interface.
    public interface ChartFacadeLocal extends IChartFacade{


  66. Johnson George says:

    Nice Joie..

  67. Nitin says:

    Ram, You are right in saying that compiler cant differentiate. Infact in the terms of marker interface, compiler has no role to play. Its only JVM who act based on the indication of marker interface NOT compiler. For example cloning is verified at runtime whether class implementing Cloneable or not. Same case with Serializable.

  68. Nitin says:

    Its not correct. compiler does not check or complain related to marker interface mandate.

  69. sree says:

    actually the clone method has the logic related to marker interface,
    mean at the time of calling the clone() on the object it checks weather the object instantiated from cloneble interface or not ,if yes it creates the copy of that obj other wise it throws checks like this.
    if(o instanceOf clonableObgect )
    according to my study

  70. abhishek says:


  71. Ram says:

    I have occasionally visited this blog in past few years. I was teaching a new developer about marker interface and was doing preparation. When I read your blog I noticed below comments
    From java 1.5 the need for marker interface is eliminated by the introduction of annotation feature. This is a common misunderstanding among lot of people. I happened to read Josh’s book Effective Java and in item 37 he clearly states the advantages of both and when to use each one of them. One difference I want to bring is
    Marker interfaces define a type that is implemented by instances of the marked class; marker annotations do not. The existence of this type allows you to catch errors at compile time that you couldn’t catch until run-time if you used a marker annotation.
    Hope I was able to add some value

  72. sita says:

    Marker interface’s definition is given in all books.This term came from books only.And moreover if you wanna make your understanding better of marker interface.You may refer Effective java by Joshua Bloch or you may refer stack overflow.Because this tutorial is correct in a way but it’s incomplete

  73. DurgaGanesh says:

    I am totally get confused. here is my queries are…..

    Can we create User-defined maker interface. ?

  74. DurgaGanesh says:

    I am totally get confused. here is my queries are…..

    Can we create User-defined maker interface. ?
    Does maker interface contains any methods or not?
    Is this true to state as “Runnable interface is marker interface” ?


  75. sita says:

    Runnable interface is not a marker interface because Runnable has a method run().Marker interfaces don’t have any methods.Marker interfaces are used to tell JVM to make class implementing marker interface to behave as per that interface.For Example,cloneable interface is a marker interface.Class implementing cloneable will tell JVM that this class can be cloned.

  76. Madhusudana says:

    Hi Joe Can U tell me the Process Of Creating My Own Marker Interface With An Example….

  77. naveenkumar says:

    please help me..
    I want my own interface as marker interface. i will implements that interface to my class, than my class as active like seriazable object…

  78. Sri says:

    Mr Joe can you explain me Is Runnable a Marker interface if it is Why

  79. Sandeep shukla says:

    Dear Joe,

    I feel I owe to you. Thanks man for such nice and simple explanation I loved it….cheers !!

  80. prasad says:

    if no methods in interface then it is marker inter face but it is wrong we can use seralizable interface to use an interface
    for example java.lang.EventListener
    public void seralizable
    void show()

  81. Anonymous says:

    I think , currently your in AKP. If your in akp , i want to meet u. please give u r contact no.

  82. rashmi ranjan jena says:

    what is markerinter face………

  83. Prasanth Pillai says:

    Hi Kavitha,

    You may use deep cloning ( Deep Copy) which gives the same purpose of Serialization.

    Prasanth Pillai

  84. […] you want to serialize an object, that respective class should implement the marker interface serializable. It just informs the compiler that this java class can be serialized. You can tag […]

  85. om kumar says:

    i think marker interface is implemented by the jvm and jvm is responsible for the object to be serialize at the runtime .in compile time jvm has no idia about the class but when its compiled then every thing is cared by the JVM

  86. Anonymous says:

    Thank u joe,i m praveen.
    plz tell me about the use of marker interface?

  87. Anonymous says:

    Does it make any vital diffrence, whether it is sending messgae/information to the compiler or JVM? This topic is all about Marker Interface and Joe explained it very well :)

  88. Divya says:

    Very good article..
    Thanq joe

  89. muthukrishnan says:

    How compiler identify this is marker interface rather than normal interface?

  90. Manibharathi says:

    Hi Joe,
    Marker Interface is verfied by compile time or Runtime?

  91. Mitul says:

    Marker interface has some special privilleges in JVM.To enforce some licence mechnisam to

    secured process.Not possible to create user defined marker interface. They areregisterd in


  92. Marker Interfaces are give about the implementing classes.

    Interface in java defines a specific behavior while class can define both behavior and state. So Interface is pure behavior and class represent state and behavior. Interfaces are used in Java to specify the behavior of classes that implement those interfaces.. interfaces in Java that have no behavior are known as marker interfaces. They have no method defined in them but are absolutely empty.

    examples of marker interfaces

    If you want to added cloneable feature in a class ,that class needs to implement Cloneable interface.
    Serialization is nothing but s saving the state of an object to persistent storage as byte stream. Serializability of a class is enabled by the class implementing the interface. Classes that do not implement this interface will not have any of their state serialized or deserialized. The serialization interface has no methods or fields .

    A tagging interface that all event listener interfaces must extend.

    Read all about Marker interface in detail here ::

  93. ramesh says:

    Hi guys,

    Anybody tell me,

    How to create MARKER INTERFACE in Java

  94. ramesh says:

    Hi guys,

    Anybody tell me,

    How to create own MARKER INTERFACE in Java

  95. ramesh says:

    Hi guys,

    Anybody tell me,

    How to create own MARKER INTERFACE in Java


  96. peeyush gupta says:

    Dear joe ,

    suppose i create marker Interface name “MyInterface”
    in this case what is the role of JVM for treating the class that implements MyInterface

  97. Tarun Soni says:

    hello sir i have one question how to make a custom marker interface . and how to show to jvm its marker interfCE AND ADD some special behavior to the class implementing

  98. Roushan Singh says:

    It’s very simple just define an interface without having any property or behaviour.
    There are many advantages of Marker Interface in which one we can see easly that we can create the object or instantiate the Interface, which is simply not possible in Java.

  99. Tarun says:

    Hi, explanation was OK. Apart from one wrong fact. Marker interface is not a term coined by books and writers. If you open source file of it is clearly written there that it is a marker interface.

  100. vasanth says:

    all are saying marker interface doesnot have any methods but it’s having two methods read() and write() . so how come it know , can u explain me?

Comments are closed for this "Java Marker Interface" tutorial.

↑ Go to top