Java SE 11 Developer (1Z0-819) — Question 164
Which two can be considered good practices for serializing Java objects? (Choose two.)
Answer options
- A. Assign null value by default while serializing and deserializing a transient variable.
- B. Ensure that the class definition used is the same as the class definition used by Java runtime at the time when the object was serialized.
- C. Always override the readObject/writeObject methods from the java.io.Serializable interface.
- D. Implement secure serialization by generating secure object hash or using encryption.
- E. Implement serialization for long-term data storage.
Correct answer: B, D
Explanation
Option B is correct because it is essential for the class definition to remain consistent to ensure proper deserialization. Option D is also correct as implementing secure serialization techniques such as hashing or encryption is crucial for protecting serialized data. Options A and C are not necessary best practices, and option E is more about a use case rather than a good practice.