Skip to content
Advertisement

Why do we need serialization if everything is already stored as bits?

From https://docs.oracle.com/javase/tutorial/jndi/objects/serial.html

To serialize an object means to convert its state to a byte stream so that the byte stream can be reverted back into a copy of the object.

Since everything is stored in memory as 0s and 1s, why is there an additional need to deconstruct an object to a form that can be transmitted over a stream? Why is the existing state not good enough for transmission?

Advertisement

Answer

If you find 01000001, how do you know if it is the number 65 or ASCII for A? Or perhaps a frequency in a wav file? It might be color information in a bitmap.
There are so many ways information can be interpreted. You must give the receiver a way of interpreting the information. My first example is perhaps a little silly. Instead, compare a CSV file with a JSON file. Try recreating a JSON structure in a CSV. It won’t be pretty.
The same logic lies behind Java’s serialization. How do you know what the class definition looks like?

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement