• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Interfaces in Java

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interfaces having nothing inside are marker interfaces but what's the use of marker interfaces.
What's there real application
 
Bartender
Posts: 2590
124
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interfaces allow for two features:
1. It creates an IS-A relationship with the implementing class (or extending interface)
2. It gives a contract for the methods that will be present in the implementing class (or extending interface)

If the Interface is empty, it effectively only gives you only #1 above. I haven't used this variant in my code at all.
However, there are interfaces such as Serializable that tells the JVM that an Object can be serialized. This interface has no methods, but it establishes an IS-A relationship nevertheless.
 
Marshal
Posts: 69495
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some people call them tagging interfaces. I suggest you start with our FAQ. Scroll down a bit and you will find it mentions marker interfaces.
 
Rancher
Posts: 892
22
Netbeans IDE Oracle MySQL Database Tomcat Server C++ Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
as already mentioned... that is_a relationship can be very important in your development--i have an interface for on of my games "displayable" do if it is implemented in the object, i know that it supports writing to the screen... besides that you can extend once... and implement as many as you want in each object.
 
Marshal
Posts: 15638
264
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might also look up alternatives to marker interfaces in Java before you decide on using them.
 
Sushant Shindes
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for your time. Now I know why it is now, I only knew what it is. I have used functional interfaces but not marker interfaces
 
Campbell Ritchie
Marshal
Posts: 69495
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Junilu Lacar wrote:You might also look up alternatives to marker interfaces in Java . . .

I tried, and rather liked this DZone link. I see Seriaizable and Cloneable there raise their ugly heads, both notorious examples of something which could have been done better.
 
Skool. Stay in. Smartness. Tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic