What is marker Interface?when it is used?


What is marker Interface?when it is used?

Marker interface is that interface which has no members in it.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. It is also known as null interface.

Definition:
“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”. 

It is used in the following scenario:
Lets take the java.io.Serializable 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 java.io.Serializable marker interface. In such way, we are intimating the java compiler. 
Java Marker Interface Examples
  • java.lang.Cloneable
  • java.io.Serializable
  • java.util.EventListener

People who read this post also read :



1 comments:

Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here.
Kindly keep blogging. If anyone wants to become a Java developer learn from Java EE Online Training from India.
or learn thru Java EE Online Training from India . Nowadays Java has tons of job opportunities on various vertical industry.

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More