Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Null vs Marker Interface

Can anyone elaborate that what is the core difference between Null interface and Marker interface in Java. I have been asked this question in one of the interview.

Thanks.

like image 558
user0 Avatar asked Jun 27 '13 11:06

user0


2 Answers

Null interface is just another name for Marker Interface or the other way round. They are used interchangeably as far as I know.

These are just interface with no methods in them. Examples of marker interfaces are : Serializable, Cloneable.

like image 111
mtk Avatar answered Oct 18 '22 16:10

mtk


Null interface is the example of marker interface.

Interface are different types. that are mainly extend interface, markble interface and marker interface.

Difference of marker Inteface and others are that marker interfaces has no methods..Example are;- serilizable-- for serialization. remote -- for remote method communication. your remote interface must extends this marker interface. when your remote interface extends marker interface then it is called as extend interface.

They just tell the compiler that the objects of this class need to be treated differently. some marker interfaces are : Serializable, Remote, Cloneable

Code:

interface markerImp 
{


}

class MarkerTest implements markerImp
{

}

public class TestInstanceOf 
{

public static void main(String []args)
{
    MarkerTest mt = new MarkerTest();
    if(mt instanceof markerImp)
{
    System.out.println("True");
}
else
{
    System.out.println("False");
}
}
}
like image 32
Manish Doshi Avatar answered Oct 18 '22 16:10

Manish Doshi