Why Serializable interface is markup interface. What exactly do this interface and how. Can you create your own markup interface for serialzing purpose. How it will behave. I know markup interface does not have any method, exactly what is the use of markup interface. and jvm how to treat this type of markup interface.
The purpose of the interface
The purpose of the interface is to signal that it's ok to serialize the state of the objects that implements the interface.
It does not make sense to serialize all fields in a class, like Object, various other classes in the SDK. (NOTE: serialization only applies to fields - not methods).
The JVM knows how to handle the serialization and it will serialize all the fields except static, final, native and transient ones.
If you need ways to control serialization process you should look into:
- private void writeObject(ObjectOutputStream out)
- private void readObject(ObjectInputStream in)
These methods, when implemented (requries no interface, has a special contract with the JVM.
You can create your own empty interfaces, but I have never personally done that!
It mean we implement
It mean we implement serializable interface of any class then we telling to JVM to treat differently then common class.
if i am wrong correct me.
Is JVM treated in differently of serializable interface implemented class? And yes then what type of action will take jvm?
I'm not sure I fully
I'm not sure I fully understand your last question.
A class that implements serializable is just a regular class after the implementation. When the JVM sees the serializable interface it knows it need to serialize every sub class also, when and if you execute code to serialize the state of the objects.
Note the point of having serializable interface is to stop the serialization process from going to far up the hierarchy of classes. As I stated earlier, it does not make sense to serialize Objects class and other JDK system classes.
Post new comment