This set of tough Java Spring Questions focuses 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
View Answer
Explanation: 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
View Answer
Explanation: 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
View Answer
Explanation: 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
View Answer
Explanation: 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
View Answer
Explanation: 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
View Answer
Explanation: 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
View Answer
Explanation: 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
View Answer
Explanation: 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
View Answer
Explanation: 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
View Answer
Explanation: The class must implement the java.io.Serializable interface.
Sanfoundry Global Education & Learning Series – Java Spring.
To practice tough questions on all areas of Java Spring, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Get Free Certificate of Merit in Spring
- Participate in Spring Certification Contest
- Become a Top Ranker in Spring
- Take Spring Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Apply for Spring Internship
- Apply for Programming Internship
- Buy Information Technology Books
- Practice Programming MCQs
- Buy Spring Books