What is Marker Interface

What is Marker Interface:
  • A interface without any member is called Marker Interface.
  • It is just an empty interface.
  • The uses of Marker Interface is to send the special message to JVM about the class
Example of Marker Interface:

when we want to make a clone of any class object then we need to send the instruction to JVM that class is eligible for cloning. we can do this by implementing the marker interface.

Interface



package com.javaforecast4u.file;

public interface JFCUCloneable {

}

 Class implemented this interface



package com.javaforecast4u.file;

public class Employee implements JFCUCloneable{
      
       int empId;
       Employee(int empId){
              this.empId = empId;
       }
       public Employee empClone() throws CloneNotSupportedException {
              if(this instanceof JFCUCloneable){
                     return new Employee(empId);
              }
              else{
                     throw new CloneNotSupportedException("Clone Not support ");
              }
       }
}

Test Class
 

package com.javaforecast4u.file;

public class MarakerInterfaceTest {

       public static void main(String[] args) throws CloneNotSupportedException{
             
              Employee emp = new Employee(1001);
              System.out.println("EmpId:"+emp.empId);
              Employee emp1 = new Employee(emp.empId);
              System.out.println("EmpId:"+emp1.empId);
              System.out.println(emp == emp1);
             
       }

}


OUTPUT:
EmpId:1001
EmpId:1001
false


10 comments :

  1. This is excellent information. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    Android training in chennai
    Ios training in chennai

    ReplyDelete
  2. Thank you for posting, its a nice post and very useful.
    Best Oracle Training in Bangalore

    ReplyDelete
  3. I really appreciate the information shared above. It’s of great help. If someone wants to learn Online (Virtual) instructor lead live training in #ALFRESCO, kindly contact us http://www.maxmunus.com/contact
    MaxMunus Offer World Class Virtual Instructor-led training on #ALFRESCO. We have industry expert trainer. We provide Training Material and Software Support. MaxMunus has successfully conducted 100000+ pieces of training in India, USA, UK, Australia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain, and UAE etc.
    Avishek Priyadarshi
    MaxMunus
    E-mail: avishek@maxmunus.com
    Skype id: avishek_2.
    Ph:(0) 8553177744 / 080 - 41103383
    http://www.maxmunus.com/

    ReplyDelete
  4. Really thanks for sharing such a great information with us.
    Also, many thanks for permitting me to comment!
    Quicken Support Number
    Quicken Online Support Number
    Quicken tech Support Number
    HP Support Number

    ReplyDelete