Advanced Java - Serialization & Reflection

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By James Richardson
J
James Richardson
Community Contributor
Quizzes Created: 13 | Total Attempts: 11,392
| Attempts: 330 | Questions: 10
Please wait...
Question 1 / 10
0 %
0/100
Score 0/100
1. Can we transfer a Serialized object via network

Explanation

Serialized objects can be transferred via a network. Serialization is the process of converting an object into a byte stream, which can be easily transmitted over a network. The byte stream can then be deserialized at the receiving end to recreate the object. This allows for the transfer of complex data structures and objects between different systems or applications.

Submit
Please wait...
About This Quiz
Advanced Topics Quizzes & Trivia

A quiz to assess the understanding of the Adv Java session in Serialization

2. True or False: To serialize an array or a collection all the members of it must be serializable

Explanation

To serialize an array or a collection, all the members of it must be serializable. Serialization is the process of converting an object into a byte stream so that it can be stored in memory, transferred over a network, or saved to a file. If any member of the array or collection is not serializable, it cannot be converted into a byte stream and therefore cannot be serialized. Therefore, the statement "To serialize an array or a collection all the members of it must be serializable" is true.

Submit
3. Can excessive use of reflection incur performance cost?

Explanation

Excessive use of reflection can indeed incur a performance cost. Reflection involves dynamically accessing and manipulating objects and their properties at runtime, which requires additional processing and can be slower compared to direct access. This can result in decreased performance and slower execution times, especially in performance-sensitive applications. Therefore, it is important to use reflection judiciously and only when necessary to avoid unnecessary performance overhead.

Submit
4. Can you customize Serialization process or can you override default Serialization process in Java?

Explanation

Yes, you can customize the serialization process in Java by implementing the Serializable interface and providing custom readObject() and writeObject() methods in your class. This allows you to have control over how the object is serialized and deserialized. Additionally, you can override the default serialization process by implementing the Externalizable interface, which gives you even more control over the serialization process.

Submit
5. Suppose super class of a new class implement Serializable interface, how can you avoid new class to being serialized?

Explanation

By implementing the writeObject() and readObject() methods in the new class, we can control the serialization process. By throwing a NotSerializableException from these methods, we can prevent the new class from being serialized. This exception will be thrown whenever an attempt is made to serialize or deserialize an object of the new class, effectively avoiding serialization.

Submit
6. SerialVersionUID of a class is subject to change if not defined by user

Explanation

The serialVersionUID of a class is a unique identifier used during serialization and deserialization to ensure that the class being serialized and the class being deserialized are compatible. If the serialVersionUID is not defined by the user, it is automatically generated based on the class's structure. This means that any changes to the class's structure, such as adding or removing fields or methods, can result in a different serialVersionUID being generated. Therefore, if the user does not define the serialVersionUID, it is subject to change.

Submit
7. How many methods does Serializable have?

Explanation

The Serializable interface does not have any methods. It is a marker interface that indicates that a class can be serialized, meaning its objects can be converted into a stream of bytes and stored or transmitted. However, it does not define any methods that must be implemented by the class. Therefore, the correct answer is "None."

Submit
8. What will happen if one of the members in the class doesn't implement Serializable interface?

Explanation

If one of the members in the class doesn't implement the Serializable interface, it will throw a run time exception. This is because when an object is being serialized, all of its members are also serialized. If a member is not serializable, it cannot be converted into a byte stream and an exception will be thrown at runtime.

Submit
9. Keeping long variable names can be costly from performance perspective while serializing and de-serializing objects

Explanation

Long variable names can be costly from a performance perspective while serializing and de-serializing objects because longer names require more memory to store and more time to process. When objects are serialized, their variable names are also stored along with their values. Longer variable names mean more data needs to be written to disk or transmitted over a network, resulting in slower serialization and de-serialization processes. Therefore, it is advisable to use shorter and more concise variable names to optimize performance in these scenarios.

Submit
10. While serializing you want some of the members not to serialize? How do you achieve it?

Explanation

By declaring a variable as static, it means that the variable belongs to the class rather than an instance of the class. Static variables are not serialized because they are not associated with any particular object. On the other hand, by declaring a variable as transient, it means that the variable should not be serialized. Transient variables are typically used for sensitive or unnecessary data that should not be persisted during serialization. Therefore, by using both static and transient declarations, we can achieve the goal of not serializing certain members.

Submit
View My Results

Quiz Review Timeline (Updated): Mar 21, 2023 +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 21, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • May 20, 2013
    Quiz Created by
    James Richardson
Cancel
  • All
    All (10)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
Can we transfer a Serialized object via network
True or False: To serialize an array or a collection all the members...
Can excessive use of reflection incur performance cost?
Can you customize Serialization process or can you override default...
Suppose super class of a new class implement Serializable interface,...
SerialVersionUID of a class is subject to change if not defined by...
How many methods does Serializable have?
What will happen if one of the members in the class doesn't...
Keeping long variable names can be costly from performance perspective...
While serializing you want some of the members not to serialize? How...
Alert!

Advertisement