Marker Interface
If an interface does not contain any methods and by implementing that interface if our object will get some ability such type of interface is called a marker interface or ability interface or tag interface.
eg-:
- Serializable(I)
- cloneable (I)
- RandomAccess(I)
- SingleThreadModel(I)
Ans-: integrally JVM is responsible to provide the required ability.
Ques-: why JVM is providing the required ability in marker interfaces ?
Ans -: to reduce the complexity of programming and to make Java language as simple.
Ques-:Is it possible to create our own marker interface?
Ans-: yes but customization of JVM is required.
Adapter classes
The adapter class is a simple Java class that implements an interface with only an empty implementation.
eg-:
interface interf{
void m2();
void m2(){}
if we implement an interface for each and every method of that interface compulsory we should provide implementation whether it is required are not required.
eg-:
void m2(){}
- the problem with this approach is it increases the length of the code and reduces its readability.
- we can solve this problem by using adopter classes.
- instead of implementing the interface if we extend the adapter class we have to provide implementation only for required methods and we are not responsible to provide implementation for each and every method of the interface so that length of the code will be reduced.
eg-:
void m1(){
}
}
void m2(){
}
}
void m3(){
}
}
void m4(){
}
}
- by implementing a servlet interface-: if we implement a servlet interface for each and every method of that interface we should provide implementation it increases the length of code and reduces readability.
- by extending the GenericServlet (AC)-: inserted of implementing servlet interface directly if we extend generic servlet we have to provide implementation only for service method and for all remaining methods not required to provide implementation .hence more are less generic servlet access adapter class for servlet interface.
- by extending the HTTPServlet (AC).