• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Marker InterFace...

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi CodeRanch Team......
I had some idea of marker interface that is its an interface with no methods, but later i came to know a marker interface may or may not have methods for example serializable is a marker interface with no methods but runnable is also a marker interface with run() method.... then later i came to a marker interface is an interface which marks the class as a special class and by doing this jvm will treat a class which implements marker interface as a special class for example if it implements runnable then jvm will treat that class as a thread.... is it so??? what ever i have understood about marker interface are right??? please explain me.......

 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What makes you think Runnable is a marker interface? The usual usage is your first definition - an interface with no methods.

Also, the JVM doesn't treat Runnable in a special way. What makes it start a new thread is the creation of a Thread object. A Runnable can be passed as an argument to the Thread.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Marker interfaces are interfaces without methods. They are used only to "mark" a class for some reason, for example you make your class implement Serializable to indicate that your class has to be serializable. Note that when you are considering creating your own marker interfaces, consider using annotations instead - they have more or less the same purpose, but are specifically made for this purpose.

Runnable is not a marker interface.

nagul samy wrote:then later i came to a marker interface is an interface which marks the class as a special class and by doing this jvm will treat a class which implements marker interface


That's not correct (making a class implement a marker interface does not necessarily mean that the JVM will treat it specially).

nagul samy wrote:for example if it implements runnable then jvm will treat that class as a thread.... is it so???


No, that is not so. Classes that implement Runnable are not treated automatically as threads.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jesper de Jong wrote:

nagul samy wrote:for example if it implements runnable then jvm will treat that class as a thread.... is it so???


No, that is not so. Classes that implement Runnable are not treated automatically as threads.



In fact there's nothing special about Runnable as far as the Java language is concerned. It's just another interface, and the way it's used by Thread and other classes is just like any other class that your or I might write would use any other interface that you or I might write.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic