A marker interface in Java is an empty interface —it has no methods or fields—and it is used to tag a class so the JVM or libraries can treat it in a special way. Common examples are Serializable, Cloneable, and Remote.

Quick scoop

Think of it like a label on a class: “this class has a certain capability.” For example, if a class implements Serializable, Java knows it can be converted into a byte stream for storage or transfer.

Why it exists

Marker interfaces are mainly used to:

  • Signal special behavior to the JVM or compiler.
  • Let frameworks or libraries apply different processing.
  • Mark classes as eligible for operations like serialization or cloning.

Example

java

interface MyMarker { }

class MyClass implements MyMarker {
}

Here, MyMarker does not define behavior; it just tags MyClass. That tag can later be checked with instanceof or used by code to decide what to do.

Common examples

Interface| What it indicates
---|---
Serializable| The object can be serialized. 17
Cloneable| The object can be cloned. 18
Remote| The object can be used in remote method calls. 15

Note

In modern Java, marker interfaces are often replaced by annotations when you only need metadata, but marker interfaces are still useful when you want the “tag” to be part of the type system.

If you want, I can also show the difference between a marker interface and an annotation in Java.