250+ TOP MCQs on Serialization in Java and Answers

tough Java Spring Questions on “Serialization in Java”.

1. Java provides a mechanism, where an object can be represented as a sequence of bytes:-
a) Serialization
b) Compilation
c) All of the mentioned
d) None of the mentioned
Answer: a
Clarification: Java provides a mechanism, called object serialization where an object can be represented as a sequence of bytes that includes the object’s data as well as information about the object’s type and the types of data stored in the object.

2. After a serialized object has been written into a file, it can be read from the file and deserialized.
a) True
b) False
Answer: a
Clarification: The type information and bytes that represent the object and its data can be used to recreate the object in memory.

3. Serialization is JVM independent.
a) True
b) False
Answer: a
Clarification: An object can be serialized on one platform and deserialized on an entirely different platform.

4. Classes which are high-level streams that contain the methods for serializing and deserializing an object.
a) ObjectInputStream
b) ObjectOutputStream
c) All of the mentioned
d) None of the mentioned
Answer: c
Clarification: Classes ObjectInputStream and ObjectOutputStream are high-level streams that contain the methods for serializing and deserializing an object.

5. The ObjectOutputStream class contains methods for writing various data types.
a) public final void writeObject(Object x)
b) public final void write(Object x)
c) public final void writeToObject(Object x)
d) all of the mentioned
Answer: a
Clarification: The ObjectOutputStream class contains many write methods for writing various data types, but one method in particular stands out:
public final void writeObject(Object x) throws IOException

6. The ObjectInputStream class contains methods for writing various data types.
a) public final Object readObject()
b) public final Object read(Object x)
c) public final Object readFromObject(Object x)
d) all of the mentioned
Answer: a
Clarification: This method retrieves the next Object out of the stream and deserializes it. The return value is Object, so you will need to cast it to its appropriate data type.

7. For a class to be serialized successfully:
a) The class must implement the java.io.Serializable interface.
b) Every field in the class must be volatile.
c) All of the mentioned
d) None of the mentioned
Answer: a
Clarification: The class must implement the java.io.Serializable interface.
All of the fields in the class must be serializable. If a field is not serializable, it must be marked transient.

8. When serializing an object to a file, the standard convention in Java is to give the file a:
a) .war
b) .java
c) .ser
d) none of the mentioned
Answer: c
Clarification: When serializing an object to a file, the standard convention in Java is to give the file a .ser extension.

9. What will be the value of transient field after deserialization:-
a) 0
b) NULL
c) All of the mentioned
d) None of the mentioned
Answer: c
Clarification: It depends on the data type of field, 0 if int and NULL if String or Object.

10. If the class implements java.io.Serializable, then it is serializable; otherwise, it’s not.
a) True
b) False
Answer: a
Clarification: The class must implement the java.io.Serializable interface.


To practice tough questions on all areas of Java Spring,

Leave a Reply

Your email address will not be published. Required fields are marked *