Which interface must be implemented to make an object serializable in Java?
ACloneable
BSerializable
CComparable
DIterable
Correct Answer:
B. Serializable
EXPLANATION
The Serializable interface must be implemented to serialize objects. It is a marker interface with no methods. Classes implementing it can be serialized using ObjectOutputStream.
What is the default buffer size used by BufferedInputStream?
A512 bytes
B1024 bytes
C8192 bytes
D4096 bytes
Correct Answer:
C. 8192 bytes
EXPLANATION
The default buffer size for BufferedInputStream is 8192 bytes (8 KB). This can be overridden by using the constructor BufferedInputStream(InputStream, int size).
Which approach would you use to read and write objects to a file efficiently in a production application?
AManually serialize each field with DataOutputStream
BUse ObjectInputStream/ObjectOutputStream with proper version control
CConvert objects to JSON and use FileWriter
DCreate custom byte arrays for each object
Correct Answer:
B. Use ObjectInputStream/ObjectOutputStream with proper version control
EXPLANATION
ObjectInputStream/ObjectOutputStream with serialVersionUID ensures compatibility, versioning, and is the standard approach for object persistence in Java.