Popular Abstract Interfaces in Java

Share and Enjoy !

Abstract interface ObjectInputValidation in Java

A class implements the ObjectInputValidation interface and defines the validateObject() method in order to be able to validate itself when it, and all the objects it depends on have been completely deserialized from an objectInputStream.

The validateObject() method is only invoked, however, if the object is passed to ObjectInputStream.registerValidation();this must be done from the readObject() method of the object.

Note that if an object is deserialized as part of a larger object graph, it’s validateObject() method is not invoked until the entire graph is read, and the original call to ObjectInputStream.readObject() is about to return.

validateObject() should throw an InvalidobjectException if the object fails validation. This stops object serialization, and causes the original call to ObjectInputStream.readObject() to terminate with the InvalidobjectException exception.

The structure of the ObjectInputValidation interface is given as

public abstract interface java.io.ObjectInputValidation{
// Public Instance Methods () 
public abstract void validateObject() throws InvalidobjectException;

Interface Cloneable in Java

The cloneable interface defines no methods or variables and provides no functionality, but indicates that the class that implements it, maybe cloned (i.e., copied) by calling the Object method clone(). Calling clone() for an object that does not implement this interface (and does not override clone() with its own implementation) causes a CloneNotSupportedException to be thrown.

READ  Common Exception Classes in Java With Example

The interface structure of Cloneable in Java is given as

public interface java.lang.Cloneable {}

Abstract Interface Member in Java

This interface Member defines the methods shared by all members (fields, methods, and constructors) of a class.
getName() returns the name of the member, getModifiers() returns its modifiers, and getDeclaringClass() returns the Class object that represents the class of which the member is a part.

The structure of the abstract inteface Member is given by

public abstract interface java.lang.reflect.Member{
// Constants
public static final int DECLARED;
public static final int PUBLIC;
// Public Instance Methods
public abstract Class getDeclaringClass();
public abstract int getModifiers();
public abstract String getName();

Share and Enjoy !

Leave a Reply

Your email address will not be published. Required fields are marked *