VOOZH about

URL: https://www.geeksforgeeks.org/java/marker-interface-in-java/

⇱ Marker Interface in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Marker Interface in Java

Last Updated : 23 Apr, 2026

A Marker Interface in Java is an interface that contains no methods or fields. It is used to mark a class so that the Java runtime or compiler can identify some special behavior or capability of that class.

Syntax:

public interface Serializable { }

Here, Serializable has no methods but if a class implements it, Java knows that objects of that class can be serialized.

Role of Marker Interfaces

Marker interfaces give information to the JVM or compiler about:

  • How to treat the object
  • What operation is allowed or disallowed
  • What special behavior should be applied

They function like a flag for the runtime environment.


Output
Person object created
Animal object created
Person is serializable
Animal is not serializable

Common Marker Interfaces in Java

There are some more real time examples of Marker Interface which are used in real-time applications. Like Cloneable Interface, Serializable interface, etc. Let us check one by one:

1. Cloneable Interface

Cloneable interface is a marker interface in java.lang that allows an object to be cloned using Object.clone(). If a class does not implement Cloneable, calling clone() on its object throws CloneNotSupportedException.


Output
20
GeeksForGeeks

2. Serializable Interface

Serializable interface is present in java.io package. It is used to make an object eligible for saving its state into a file. This is called Serialization. Classes that do not implement serializable will not have their state serialized or deserialized. All subtypes of a serializable class are themselves serializable.


Output
20 GeeksForGeeks

3. Remote Interface

Remote interface (in java.rmi) is a marker interface that identifies objects whose methods can be invoked remotely from another JVM. Any class implementing Remote is eligible to be used in Java RMI, allowing distributed communication between systems.

Explanation: Extending Remote marks the interface as eligible for remote invocation. Each remote method must declare throws RemoteException.

Comment
Article Tags:
Article Tags: