File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes marker interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "marker interface" Watch "marker interface" New topic

marker interface

Naga Niranjan

Joined: Aug 02, 2005
Posts: 25
what is marker interface? give me some examples?
Mahen Rathod

Joined: Apr 10, 2006
Posts: 5
Hi Find the example below it may help you out about marker interface.

The Purpose of the Marker Interface:

One of the "clean" features of the Java programming language is that it mandates a separation between interfaces (pure behavior) and classes (state and behavior). Interfaces are used in Java to specify the behavior of derived classes.

Often you come across interfaces in Java that have no behavior. In other words, they are just empty interface definitions. These are known as marker interfaces. Some examples of marker interfaces in the Java API include:

- java,lang.Cloneable
- java,io.Serializable
- java.util.EventListener

Marker interfaces are also called "tag" interfaces since they tag all the derived classes into a category based on their purpose. For example, all classes that implement the Cloneable interface can be cloned (i.e., the clone() method can be called on them). The Java compiler checks to make sure that if the clone() method is called on a class and the class implements the Cloneable interface. For example, consider the following call to the clone() method on an object o:

SomeObject o = new SomeObject();
SomeObject ref = (SomeObject)(o.clone());

If the class SomeObject does not implement the interface Cloneable (and Cloneable is not implemented by any of the superclasses that SomeObject inherits from), the compiler will mark this line as an error. This is because the clone() method may only be called by objects of type "Cloneable." Hence, even though Cloneable is an empty interface, it serves an important purpose.

Warm Regards,
Mahen Rathod
Naga Niranjan

Joined: Aug 02, 2005
Posts: 25
Thank u. And now i need some information that what are the marker interfaces in package java.lang in 1.5V
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
The Java Intermediate FAQ also talks about marker interfaces.

If you want to know which ones are in a particular package, you can just look through the javadocs. There aren't that many interfaces.
I agree. Here's the link:
subject: marker interface
It's not a secret anymore!