View Tanya  Sharma 's Profile
What is Marker interface? How is it used in Java?
The marker interface is a design pattern, used with languages that provide run-time type information about objects. It provides a way to associate metadata with a class where the language does not have explicit support for such metadata. To use this pattern, a class implements a marker interface, and code that interact with instances of that class test for the existence of the interface. Whereas a typical interface specifies functionality (in the form of method declarations) that an implementing class must support, a marker interface need not do so. The mere presence of such an interface indicates specific behavior on the part of the implementing class. There can be some hybrid interfaces, which both act as markers and specify required methods, are possible but may prove confusing if improperly used. Java utilizes this pattern very well and the example interfaces are

java.io.Serializable - Serializability of a class is enabled by the class implementing the java.io.Serializable interface. Classes that do not implement this interface will not have any of their state serialized or deserialized. All subtypes of a serializable class are themselves serializable. The serialization interface has no methods or fields and serves only to identify the semantics of being serializable.
java.rmi.Remote - The Remote interface serves to identify interfaces whose methods may be invoked from a non-local virtual machine. Any object that is a remote object must directly or indirectly implement this interface. Only those methods specified in a "remote interface", an interface that extends java.rmi.Remote are available remotely.
java.lang.Cloneable - A class implements the Cloneable interface to indicate to the Object.clone() method that it is legal for that method to make a field-for-field copy of instances of that class. Invoking Object's clone method on an instance that does not implement the Cloneable interface results in the exception CloneNotSupportedException being thrown.
javax.servlet.SingleThreadModel - Ensures that servlets handle only one request at a time. This interface has no methods.
java.util.EvenListener - A tagging interface that all event listener interfaces must extend.

The "instanceof" keyword in java can be used to test if an object is of a specified type. So this keyword in combination with Marker interface can be used to take different actions based on type of interface an object implements.
Asked by Tanya Sharma | Nov 11 2017 | Report this Report abuse
Replies (5)
View Roshan  shah 's Profile
Why there are two Date classes; one in java.util package and another in java.sql?
Nov 19 2017 | Report this Report abuse
View Havish  Goswami 's Profile
From the JavaDoc of java.sql.Date:

A thin wrapper around a millisecond value that allows JDBC to identify this as an SQL DATE value. A milliseconds value represents the number of milliseconds that have passed since January 1, 1970 00:00:00.000 GMT. To conform with the definition of SQL DATE, the millisecond values wrapped by a java.sql.Date instance must be 'normalized' by setting the hours, minutes, seconds, and milliseconds to zero in the particular time zone with which the instance is associated.
Nov 18 2017 | Report this Report abuse
View Diksha  Basu 's Profile
Now a days annotations are recommended in favor of marker interfaces but still marker interfaces have their own significance as explained in my blog post on marker interfaces
Nov 17 2017 | Report this Report abuse
View Shivendu  Chatterjee 's Profile
Now a days annotations are recommended in favor of marker interfaces but still marker interfaces have their own significance as explained in my blog post on marker interfaces
Nov 17 2017 | Report this Report abuse
View Khushi   Kumari 's Profile
difference between java.sql.Date and java.util.Date. In summary sql date represent only Date information (e.g. year, month, day) while util Date represent both date and time information(e.g. year, month, day + time)
Nov 17 2017 | Report this Report abuse