Skip to main content

Posts

Showing posts with the label Marker Interface

Why Marker Interface Does Not Have Method Declarations?

Every Java programmer knows that Marker Interface does not have any methods in it. Some of you confused if there are no any method declarations, and then what is the use of Marker Interface or Tagged Interface. But very few people know why we use Marker Interface and its use in our programs. Whenever any class implementing some Marker Interface, just we are telling to JVM to do that particular functionality of interface. So JVM checks that class or it's super class is implementing the Serializable interface or not. That means serialization process is taken care by JVM itself. So you no need to write any code for serialization. Then what is the use of method declarations in Serializable interface when JVM is going to do everything for us.

What is Bridge Pattern and Marker Interface

Bridge Pattern as the name suggests is used maily to decouple the interface and the class implementing the interface. Another obvious advantage is the extensibility provided in terms of Future enhancements. Also, hiding the actual implementation from the Client. Marker Interfaces are interfaces in Java that have no behavior. In other words, they are just empty interface definitions. For example in the Java API java.io.Serializable, Cloneable etc. All interfaces can act as marker interface but null interfaces are the most suited for it. also every interface has a boolean flag and that boolean flag goes for the entire generation of classes implenting that interface. I understand this boolean flag is the marker. What I want to know how this stuff is working in detail? Marker Interface: One of the "clean" features of the Java programming language is that it mandates a separation between interfaces (pure behavior) and classes (state and behavior). Interfaces are used in Ja...