Serializable Interface in Java Last Updated : 24 Nov, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report The Serializable interface is present in java.io package. It is a marker interface. A Marker Interface does not have any methods and fields. Thus classes implementing it do not have to implement any methods. Classes implement it if they want their instances to be Serialized or Deserialized. Serialization is a mechanism of converting the state of an object into a byte stream. Serialization is done using ObjectOutputStream. Deserialization is the reverse process where the byte stream is used to recreate the actual Java object in memory. This mechanism is used to persist the object. Deserialization is done using ObjectInputStream. Thus it can be used to make an eligible for saving its state into a file. Declaration public interface Serializable Example: The below example shows a class that implements Serializable Interface. Java // Java Program to demonstrate a class // implementing Serializable interface import java.io.Serializable; public static class Student implements Serializable { public String name = null; public String dept = null; public int id = 0; } Here, you can see that Student class implements Serializable, but does not have any methods to implement from Serializable. Example: Below example code explains Serializing and Deserializing an object. Java // Java program to illustrate Serializable interface import java.io.*; // By implementing Serializable interface // we make sure that state of instances of class A // can be saved in a file. class A implements Serializable { int i; String s; // A class constructor public A(int i, String s) { this.i = i; this.s = s; } } public class Test { public static void main(String[] args) throws IOException, ClassNotFoundException { A a = new A(20, "GeeksForGeeks"); // Serializing 'a' FileOutputStream fos = new FileOutputStream("xyz.txt"); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(a); // De-serializing 'a' FileInputStream fis = new FileInputStream("xyz.txt"); ObjectInputStream ois = new ObjectInputStream(fis); A b = (A)ois.readObject(); // down-casting object System.out.println(b.i + " " + b.s); // closing streams oos.close(); ois.close(); } } Output: 20 GeeksForGeeks Must Read: Serialization and Deserialization in Java Comment More infoAdvertise with us Next Article Java Runnable Interface G Ganeshchowdharysadanala Follow Improve Article Tags : Java Java-Collections Java-I/O Practice Tags : JavaJava-Collections Similar Reads Java Runnable Interface java.lang.Runnable is an interface that is to be implemented by a class whose instances are intended to be executed by a thread. There are two ways to start a new Thread - Subclass Thread and implement Runnable. There is no need to subclass a Thread when a task can be done by overriding only the run 3 min read Marker Interface in Java In Java, a marker Interface is an empty interface that has no fields or methods. It is used just to mark or tag a class to tell Java or other programs something special about that class. These interfaces do not have any methods inside but act as metadata to provide information about the class. Examp 4 min read Nested Interface in Java In Java, we can declare interfaces as members of a class or another interface. Such an interface is called a member interface or nested interface. Interfaces declared outside any class can have only public and default (package-private) access specifiers. In Java, nested interfaces (interfaces declar 5 min read TransferQueue Interface in Java The TransferQueue interface is a member of the Java Collections Framework. It was introduced in JDK 1.7, it belongs to java.util.concurrent package. The TransferQueue is a BlockingQueue in which a sending thread(producer) may wait for the receiving thread(consumers) to receive elements. TransferQueu 8 min read Private Methods in Java 9 Interfaces Java 9 onwards, you can include private methods in interfaces. Before Java 9 it was not possible. Interfaces till Java 7 In Java SE 7 or earlier versions, an interface can have only two things i.e. Constant variables and Abstract methods. These interface methods MUST be implemented by classes which 4 min read Java List Interface The List Interface in Java extends the Collection Interface and is a part of the java.util package. It is used to store the ordered collections of elements. In a Java List, we can organize and manage the data sequentially. Key Features:Maintained the order of elements in which they are added.Allows 15+ min read Like