Marker Interface
It is an empty interface (no field or methods). Examples of marker interface are Serializable, Clonnable & Remote interface. All these interfaces are empty interfaces.
public interface Serializable {
// nothing here
}
Marker interfaces can be replaced with annotations in many places.
Examples of Marker Interface which are used in real-time applications :
}
Marker interfaces can be replaced with annotations in many places.
Examples of Marker Interface which are used in real-time applications :
Cloneable interface : @Clonnable
Cloneable interface is present in java.lang package. There is a method clone() in Object class. A class that implements the Cloneable interface indicates that it is legal for clone() method to make a field-for-field copy of instances of that class. This interface tells the JVM that object of the implementing class can be cloned so please prepare the object in such a way that it can support the cloning feature.
Serializable interface : @Serializable
Serializable interface is present in java.io package. It is used to make an object eligible for saving its state into a file. This is called Serialization.
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.
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.
Lets understand the use of Serializable interface: Lets say in a application we have 1000 value objects.We want to serialize only 100 specific objects . Now JDK has said that programmer role is just to mark the object as special with marker interface in this case its serializable interface.Now JDK will take care of that which object to serialize or not?
Yes we could achieve this kind of behavior with some kind of boolean flag . but that would be a bad approach.
Remote interface : @Remote
Remote interface is present in java.rmi package. A remote object is an object which is stored at one machine and accessed from another machine. So, to make an object a remote object, we need to flag it with Remote interface. Here, 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. RMI (Remote Method Invocation) provides some convenience classes that remote object implementations can extend which facilitate remote object creation.
REFERENCES :
Comments
Post a Comment