serializable is a special interface that specifies that class is serialiazable. It's special in that unlike a normal interface it does not define any methods that must be implemented: it is simply marking the class as serializable. For more info see the Java docs.

As to what "serializable" means it simply means converting an instance of a class (an object) into a format where it can be written to disk, or possibly transmitted over a network. You could for example save your object to disk and reload it later, with all the field values and internal state saved. See the wikipedia page for more info.

Answer from Richard H on Stack Overflow
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › io › Serializable.html
Serializable (Java Platform SE 8 )
March 16, 2026 - Serializability of a class is enabled by the class implementing the java.io.Serializable interface. Classes that do not implement this interface will not have any of their state serialized or deserialized. All subtypes of a serializable class are themselves serializable.
People also ask

What happens if a class does not implement the Serializable interface in Java, but serialization is attempted?
If a class does not implement the Serializable interface and you try to serialize its objects, Java will throw a NotSerializableException. This is because the serialization mechanism relies on this marker interface to confirm that the class is explicitly allowing its instances to be serialized. Without this, Java prevents serialization to avoid unintended behavior or data corruption.
🌐
upgrad.com
upgrad.com › home › blog › software development › understanding the serializable in java: serializable interface with examples
Serializable in Java: Complete Guide with Examples
Can you serialize objects that contain references to non-serializable classes?
No, Java serialization requires that all objects referenced directly or indirectly by the object being serialized must themselves implement Serializable. If the serializer encounters a non-serializable object, it throws a NotSerializableException. To handle this, you can mark such fields as transient to exclude them or provide custom serialization methods to manage their state separately.
🌐
upgrad.com
upgrad.com › home › blog › software development › understanding the serializable in java: serializable interface with examples
Serializable in Java: Complete Guide with Examples
Can static fields be serialized in Java?
No, static fields belong to the class itself rather than any individual object instance. Since serialization captures the state of a specific object, static fields are excluded because their value is shared across all instances and maintained separately in the class memory area. If you want to persist static data, you need to handle it separately outside the serialization mechanism.
🌐
upgrad.com
upgrad.com › home › blog › software development › understanding the serializable in java: serializable interface with examples
Serializable in Java: Complete Guide with Examples
🌐
Reddit
reddit.com › r/javahelp › explain like i'm five - what is serializable?
r/javahelp on Reddit: Explain like i'm five - what is Serializable?
April 26, 2024 -

I just don't get it. I'm a junior and see it often in the codebase of the company i work at. Documentation says that it helps serialize and deserialize objects, but why does that need to happen using this interface? There are so many classes that do not implement Serializable, so what happens to them?
Head First Java book says that objects need to be serialized when data is sent over the network or saved to a disk. But there is serialization/deserialization happening to JSON objects for example when they're being sent from server to client and vice versa, and those classes do not implement Serializable.
So in which "special" scenario does one need/want to implement Serializable?

🌐
Oracle
docs.oracle.com › javase › 8 › docs › technotes › guides › serialization › index.html
Java Object Serialization
March 16, 2026 - Java SE 8 Documentation · Search · Object Serialization supports the encoding of objects and the objects reachable from them, into a stream of bytes. Serialization also supports the complementary reconstruction of the object graph from a stream. Serialization is used for lightweight persistence ...
🌐
Tutorialspoint
tutorialspoint.com › java › java_serialization.htm
Java - Serialization
Java 8 - Questions and Answers ... where an object can be represented as a sequence of bytes that includes the object's data as well as information about the object's type and the types of data stored in the object...
🌐
GeeksforGeeks
geeksforgeeks.org › serialization-in-java
Serialization and Deserialization in Java with Example | GeeksforGeeks
January 4, 2025 - Only the objects of those classes can be serialized which are implementing java.io.Serializable interface. Serializable is a marker interface (has no data member and method). It is used to "mark" java classes so that objects of these classes ...
🌐
Baeldung
baeldung.com › home › java › core java › introduction to java serialization
Introduction to Java Serialization | Baeldung
May 11, 2024 - This method takes a serializable object and converts it into a sequence (stream) of bytes. Similarly, the most important method in ObjectInputStream is: public final Object readObject() throws IOException, ClassNotFoundException; This method can read a stream of bytes and convert it back into a Java object.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › java › serializable-interface-in-java
Serializable Interface in Java - GeeksforGeeks
July 23, 2025 - 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.
🌐
nipafx
nipafx.dev › why-isnt-java-optional-serializable
Why Isn't Optional Serializable? - nipafx.dev
October 22, 2014 - Java 8's new type Optional was met with different reactions and one point of criticism is that it isn't serializable. Let's have a look at the reasons for that.
🌐
Upgrad
upgrad.com › home › blog › software development › understanding the serializable in java: serializable interface with examples
Serializable in Java: Complete Guide with Examples
August 8, 2025 - Java objects can’t be stored or transmitted directly due to JVM-managed memory, which keeps them in a format specific to the Java Virtual Machine. Serialization bridges this gap by converting an object’s state into a sequence of bytes, making it platform-independent and enabling easy storage or transmission across systems.
🌐
Oracle
docs.oracle.com › javase › tutorial › jndi › objects › serial.html
Serializable Objects (The Java™ Tutorials > Java Naming and Directory Interface > Java Objects in the Directory)
When an object is serialized, information that identifies its class is recorded in the serialized stream. However, the class's definition ("class file") itself is not recorded. It is the responsibility of the system that is deserializing the object to determine how to locate and load the necessary class files. For example, a Java application might include in its classpath a JAR file that contains the class files of the serialized object(s) or load the class definitions by using information stored in the directory, as explained later in this lesson.
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › io › Serializable.html
Serializable (Java Platform SE 7 )
Serializability of a class is enabled by the class implementing the java.io.Serializable interface. Classes that do not implement this interface will not have any of their state serialized or deserialized. All subtypes of a serializable class are themselves serializable.
Top answer
1 of 16
2615

The docs for java.io.Serializable are probably about as good an explanation as you'll get:

The serialization runtime associates with each serializable class a version number, called a serialVersionUID, which is used during deserialization to verify that the sender and receiver of a serialized object have loaded classes for that object that are compatible with respect to serialization. If the receiver has loaded a class for the object that has a different serialVersionUID than that of the corresponding sender's class, then deserialization will result in an InvalidClassException. A serializable class can declare its own serialVersionUID explicitly by declaring a field named serialVersionUID that must be static, final, and of type long:

ANY-ACCESS-MODIFIER static final long serialVersionUID = 42L;

If a serializable class does not explicitly declare a serialVersionUID, then the serialization runtime will calculate a default serialVersionUID value for that class based on various aspects of the class, as described in the Java(TM) Object Serialization Specification. However, it is strongly recommended that all serializable classes explicitly declare serialVersionUID values, since the default serialVersionUID computation is highly sensitive to class details that may vary depending on compiler implementations, and can thus result in unexpected InvalidClassExceptions during deserialization. Therefore, to guarantee a consistent serialVersionUID value across different java compiler implementations, a serializable class must declare an explicit serialVersionUID value. It is also strongly advised that explicit serialVersionUID declarations use the private modifier where possible, since such declarations apply only to the immediately declaring class — serialVersionUID fields are not useful as inherited members.

2 of 16
525

If you're serializing just because you have to serialize for the implementation's sake (who cares if you serialize for an HTTPSession, for instance...if it's stored or not, you probably don't care about de-serializing a form object), then you can ignore this.

If you're actually using serialization, it only matters if you plan on storing and retrieving objects using serialization directly. The serialVersionUID represents your class version, and you should increment it if the current version of your class is not backwards compatible with its previous version.

Most of the time, you will probably not use serialization directly. If this is the case, generate a default SerialVersionUID by clicking the quick fix option and don't worry about it.

🌐
DigitalOcean
digitalocean.com › community › tutorials › serialization-in-java
Serialization in Java - Java Serialization | DigitalOcean
August 3, 2022 - If you want a class object to be serializable, all you need to do it implement the java.io.Serializable interface. Serializable in java is a marker interface and has no fields or methods to implement. It’s like an Opt-In process through which we make our classes serializable.
🌐
Hacker News
news.ycombinator.com › item
Only Java's built-in serialization still requires Serializable. And Java's built... | Hacker News
February 11, 2025 - Newer libraries dropped the need for Serializable, because whether or not an object is serializable is not just dependent on its class, but also on the features the serialization library supports · If you added "...for public APIs" then I would agree. But that represents only a tiny portion ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › serialization-and-deserialization-in-java
Serialization and Deserialization in Java - GeeksforGeeks
June 2, 2025 - Serializable Interface: If we want to make a class serializable, then it must implement the Serializable interface. This interface does not contain any methods or variables ( marker interface), but it gives a signal that the class is ready for ...
Top answer
1 of 8
212

This answer is in response to the question in the title, "Shouldn't Optional be Serializable?" The short answer is that the Java Lambda (JSR-335) expert group considered and rejected it. That note, and this one and this one indicate that the primary design goal for Optional is to be used as the return value of functions when a return value might be absent. The intent is that the caller immediately check the Optional and extract the actual value if it's present. If the value is absent, the caller can substitute a default value, throw an exception, or apply some other policy. This is typically done by chaining fluent method calls off the end of a stream pipeline (or other methods) that return Optional values.

It was never intended for Optional to be used other ways, such as for optional method arguments or to be stored as a field in an object. And by extension, making Optional serializable would enable it to be stored persistently or transmitted across a network, both of which encourage uses far beyond its original design goal.

Usually there are better ways to organize the data than to store an Optional in a field. If a getter (such as the getValue method in the question) returns the actual Optional from the field, it forces every caller to implement some policy for dealing with an empty value. This will likely lead to inconsisent behavior across callers. It's often better to have whatever code sets that field apply some policy at the time it's set.

Sometimes people want to put Optional into collections, like List<Optional<X>> or Map<Key,Optional<Value>>. This too is usually a bad idea. It's often better to replace these usages of Optional with Null-Object values (not actual null references), or simply to omit these entries from the collection entirely.

2 of 8
16

A lot of Serialization related problems can be solved by decoupling the persistent serialized form from the actual runtime implementation you operate on.

/** The class you work with in your runtime */
public class My implements Serializable {
    private static final long serialVersionUID = 1L;

    Optional<Integer> value = Optional.empty();

    public void setValue(Integer i) {
        this.value = Optional.ofNullable(i);
    }

    public Optional<Integer> getValue() {
        return value;
    }
    private Object writeReplace() throws ObjectStreamException
    {
        return new MySerialized(this);
    }
}
/** The persistent representation which exists in bytestreams only */
final class MySerialized implements Serializable {
    private final Integer value;

    MySerialized(My my) {
        value=my.getValue().orElse(null);
    }
    private Object readResolve() throws ObjectStreamException {
        My my=new My();
        my.setValue(value);
        return my;
    }
}

The class Optional implements behavior which allows to write good code when dealing with possibly absent values (compared to the use of null). But it does not add any benefit to a persistent representation of your data. It would just make your serialized data bigger…

The sketch above might look complicated but that’s because it demonstrates the pattern with one property only. The more properties your class has the more its simplicity should be revealed.

And not to forget, the possibility to change the implementation of My completely without any need to adapt the persistent form…

🌐
Quora
quora.com › How-is-an-object-is-serialized-in-Java
How is an object is serialized in Java? - Quora
Serializable interface Serializable in java is a marker interface and has no fields or methods to implement. Love this answer don’t forget to Upvote and follow for more content, Have any more qu...
🌐
Oracle
docs.oracle.com › javase › 8 › docs › platform › serialization › spec › class.html
Java Object Serialization Specification: 4 - Class Descriptors
1 day ago - For serializable classes, the SC_SERIALIZABLE flag is set, the number of fields counts the number of serializable fields and is followed by a descriptor for each serializable field. The descriptors are written in canonical order. The descriptors for primitive typed fields are written first ...
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › serialized-form.html
Serialized Form (Java Platform SE 8 )
October 20, 2025 - This represent the currentSerialVersion which is bein used. It will be one of two values : 0 versions before Java 2 platform v1.2.. 1 versions after Java 2 platform v1.2.. ... Reads the ObjectInputStream. Unrecognized keys or values will be ignored. ... Writes default serializable fields to a stream.