Here i am writing some simple and easy understandable points related to marker interface ,which will be useful in java interview..
1.what is marker interface?
An interface called as marker interface which does not contain any method definition(s) and field declaration(s) in it.
2.Name some marker interfaces available in java?
-java.lang.Cloneable
-java.io.Serializable
-java.util.EventListener
3.why do we need marker interface in java?
In java marker interface direct's to the JVM to do some special operation like cloning,serialization
4.can we write our own marker interface in java?
Yes we can write but not recommended by the java team
5.How the Java compiler identify normal classes and Java classes implementing these marker interfaces even though the marker interface does not have any members?
Java compiler won’t recognize the interface is a marker interface or not,only Java JVM will recognize it with instanceOf() .If we are using Cloning concept to clone object without implementing that class to the Cloneable marker interface then we will get a runtime exception saying CloneNotSupportedException.
6.Alternative to marker interfaces?
-Internal flags can be used instead of marker interfaces to indicate any special operation.
-Annotations are recommended instead of marker interfaces to indicate any special operation.