Flag Interface?

hi
  I heard about Flag interfaces ,which does not have any methods in them.What is their significane.

Thanks in advance
ngijane
 
ngijaneAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Ravindra76Connect With a Mentor Commented:

An interface may be defined as the contract that must be executed by implementators.

Flag interface have no implementation but they have specific importance in implementing them.

First one consider the Serialization interface.

You have to make a difference between serializable and non serializable.

How?

By executing a contract.

Now Serializable contract will distinguish the the serializable and non serializable objects .

And Serializable may proudly say that they are Serializable since they have implemented the contract "Serializable".

IN this purpose , no need of methods to distiguish. If You provide the methos, you have to implement them.

But here Just to distinguish two objects, why introducing again unnecessary methods and implement it?.
So no methods.

But any how by implementing that interface, Serializable interfaces have executed the contract.

Same is true for Remote.

Beacuse you have to distinguish the Remote interface and Ordinary interface.

That's why they are implemnting Remote interface.

In this case also providing methods is meaning less.

Take another example of JSDK2.0

Since each service method is a thread, user has to take care of Concurrent access to shared resources in running servlet which will create multiple threads for multiple requests by calling service method (or any doPost or doGet ).

Then Sun introduced SingleThreadModel.

By implementiing that interface, service method of servlet take care of synchronization of resources among multiple threads.

Here also no special behaviour is needed to distinguish between SingeThread and MultipleThreads running. That's why no method in tht interface.


Best of luck
0
 
sgomsCommented:
There are a few interfaces called as Marker Interfaces(FlagInterfaces) which do not have any methods in them.

Serializable is one such interface. what it does is instructs teh compiler & then teh run time environment to perform a certain operation. In case of serializable all the vraiables , objects are serialized(convereted to bytes) & can be used by ObjectInout/output streams for their purposes.

Remote is another marker interface in the java.rmi package which qualifies the interface as a remote object.

-sgoms
0
 
ngijaneAuthor Commented:
hi
 ravindra
          Thanks for the info..I got it ngijane.
0
All Courses

From novice to tech pro — start learning today.