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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is Deserialization

A

byte stream -> java object in memory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

‘static’ member

A

No

  1. Static variables belong to a class and not to any individual instance.
  2. The concept of serialization is concerned with the object’s current state. Only data associated with a specific instance of a class is serialized,
  3. therefore static member fields are ignored during serialization
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

‘transient’ member

A

serialization - > The value will be ignored

Deserialization -> value is null(default value)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

‘final’ + ‘transient’ member

A

serialization - > The value will NOT be ignored

Deserialization -> value exists

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

serialVersionUID

A
  1. private static final long serialVersionUID = 1L;
  2. InvalidClassException - If there is a difference between serialVersionUID of loaded receiver class and corresponding sender class then InvalidClassException will be thrown
  3. no serialVersionUID field defined explicitly - serialization runtime will calculate default value for that class. Which can vary based on compiler implementation
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Why Java serialisation is bad performance

A

implements Serializable:

  1. Expend object size
  2. using reflection very slow
  3. create a lot of temp obj/gabbage

Best practice/alternatives?
Protobuf

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What kind of exception will be thrown if some field is not serializable? How to handle it?

A

TO_DO

How well did you know this?
1
Not at all
2
3
4
5
Perfectly