• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Marker Interface

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Marker Interface there are no method so Why we are implements marker interface in the class if there no method in marker interface.

Can anybody clear my this doubt
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This topic has been discussed many, many times, e.g. here and here. Please use the Search link at the top of the page to find the other discussions.
 
Ranch Hand
Posts: 341
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The answer lies in the basics of Java. We know that interfaces define pure behavior, and classes define state as well as behavior. Now, Interfaces are used to specify the behavior of classes derieved.

There are scenarios when we don't want the user to do any specific coding, but we want that behaviour to be achieved. In these cases the Marker Interface comes into action. When we implement a marker interface, we get the features incorporated in it, without writing any piece of code. Another important keyword in this context is the Tagged Interface.

Now, examples of Marker interface are
- java,lang.Cloneable
- java,io.Serializable
- java.util.EventListener

All, these are Marker interfaces and once you implement them in your class you get the appropriate behaviour.

When a .clone() call is made on an object the Java compiler makes sure that the class implements the Cloneable interface.

Hope this helps.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

There are scenarios when we don't want the user to do any specific coding, but we want that behaviour to be achieved. In these cases the Marker Interface comes into action. When we implement a marker interface, we get the features incorporated in it, without writing any piece of code.


Just being picky here, but somebody, somewhere, of course had to write code to handle the functionality. It's just not in the class that implements the interface. E.g., for Serializable the implementing code is in the class libraries, while for Cloneable it's part of the JVM.
 
Anubhav Anand
Ranch Hand
Posts: 341
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the added info UD.
 
Ranch Hand
Posts: 79
Eclipse IDE Spring Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote: .. E.g., for Serializable the implementing code is in the class libraries, while for Cloneable it's part of the JVM.



very important info. thanks.
 
Tomorrow is the first day of the new metric calendar. Comfort me tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic