What exactly does it mean for a class to be Serializable
in Java? Or in general, for that matter...
views:
136answers:
5It means that instances of the class can be turned into a byte-stream (for example, to be saved to a file) and then converted back into classes again. This reloading could happen in a different instance of the program, or even on a different machine. Serialisation (in any language) involves all sorts of issues, though, especially when you've got references to other objects inside the serialisable one.
Serialization is persisting an object from memory to a sequence of bits, for instance for saving onto the disk. Deserialization is the opposite - reading data from the disk to hydrate/create an object.
In the context of your question, it is an interface that if implements in a class, means that it can be automatically be serialized and deserialized by the different serializers.
Serializable is called in like an interface but its more like a flag to the compiler. It says this object can be saved. All the Objects instance variables with the exception of none serializable objects and ones mark volatile will be saved.
Imagine your application can change colour as an option, without keeping that setting external you would need to change the colour every time you ran it.
Serialization involves saving the current state of an object to a stream, and restoring an equivalent object from that stream. The stream functions as a container for the object
Just to add to the other answers and with regards to generality. Serialization is sometimes known as archiving, for example in Objective-C.