Serialisation Flashcards
1
Q
What is Serialization
A
1.state of an object -> byte stream
2. can be saved to:
DB
Disk
Transferred over network
2
Q
What is Deserialization
A
byte stream -> java object in memory
3
Q
‘static’ member
A
No
- Static variables belong to a class and not to any individual instance.
- The concept of serialization is concerned with the object’s current state. Only data associated with a specific instance of a class is serialized,
- therefore static member fields are ignored during serialization
4
Q
‘transient’ member
A
serialization - > The value will be ignored
Deserialization -> value is null(default value)
5
Q
‘final’ + ‘transient’ member
A
serialization - > The value will NOT be ignored
Deserialization -> value exists
6
Q
serialVersionUID
A
- private static final long serialVersionUID = 1L;
- InvalidClassException - If there is a difference between serialVersionUID of loaded receiver class and corresponding sender class then InvalidClassException will be thrown
- no serialVersionUID field defined explicitly - serialization runtime will calculate default value for that class. Which can vary based on compiler implementation
7
Q
Why Java serialisation is bad performance
A
implements Serializable:
- Expend object size
- using reflection very slow
- create a lot of temp obj/gabbage
Best practice/alternatives?
Protobuf
8
Q
What kind of exception will be thrown if some field is not serializable? How to handle it?
A
TO_DO