What is Serializable in Java?

Possible duplicate:
What does Serializable mean?

I have

class Person implements Serializable { } 

what is it and what happens if i just use

 class Person { } 
+7
source share
7 answers

serializable is a special interface that indicates that the class is serialiazable. It differs in that, unlike the usual interface, it does not define any methods that should be implemented: it simply marks the class as serializable. For more information, see Java docs .

As for what “serializable” means, it simply means converting an instance of a class (object) into a format where it can be written to disk or possibly transferred over a network. You can, for example, save your object to disk and reload it later, with all field values ​​and internal state saved. For more information, see the Wikipedia page .

+12
source

If you never serialize an instance of Person , it makes no sense to declare implements Serializable . But if you do not and try to serialize the instance, you will get a NotSerializableException .

+6
source

Serialization provides data transmission over the network and can be saved and restored to its original state using the serialization / de-serialization mechanism.

+3
source

This is basically a marker interface that says your class can be serialized. See here for more details.

+1
source

It is a marker interface to declare this class as serializable . You must google for “serializing Java,” as this issue has been covered in hundreds of tutorials and articles. You can even start right on Wikipedia . In a nutshell, serialization is reading and writing entire graphs of objects from / to streams, such as files or network sockets.

+1
source

Serializable is just a marker interface. It is completely empty. It simply allows the serialization engine to verify that the class can be saved.

Also see the following. Why Java requires a Serializable interface?

+1
source

J2SE doc says:

The serializability of the class is activated by the class that implements the java.io.Serializable interface. Classes that do not implement this interface will not have their serialized or deserialized state . All subtypes of a serializable class are themselves serializable. The serialization interface has no methods or fields and serves only to identify the semantics of serialization.

Basically, this is an interface that you must implement to serialize classes in java.

0
source

All Articles