Advanced Java - Serialization & Reflection

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By James Richardson
J
James Richardson
Community Contributor
Quizzes Created: 13 | Total Attempts: 10,987
Questions: 10 | Attempts: 320

SettingsSettingsSettings
Java Quizzes & Trivia

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


Questions and Answers
  • 1. 

    How many methods does Serializable have?

    • A.

      One

    • B.

      Two

    • C.

      Three

    • D.

      None

    Correct Answer
    D. None
    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."

    Rate this question:

  • 2. 

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

    • A.

      Yes

    • B.

      No

    Correct Answer
    A. Yes
    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.

    Rate this question:

  • 3. 

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

    • A.

      By declaring variable static

    • B.

      Be declaring variable transient

    • C.

      Both of the above

    • D.

      None of the above

    Correct Answer
    C. Both of the above
    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.

    Rate this question:

  • 4. 

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

    • A.

      Will throw compilation time issue

    • B.

      Will throw run time exception

    • C.

      Will serialize all members except non serializable membe

    • D.

      None of the above

    Correct Answer
    B. Will throw run time exception
    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.

    Rate this question:

  • 5. 

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

    • A.

      Yes

    • B.

      No

    Correct Answer
    A. Yes
    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.

    Rate this question:

  • 6. 

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

    • A.

      Not possible

    • B.

      Implement writeObject() and readObject() method in your Class and need to throw NotSerializableException from those method.

    Correct Answer
    B. Implement writeObject() and readObject() method in your Class and need to throw NotSerializableException from those method.
    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.

    Rate this question:

  • 7. 

    Can we transfer a Serialized object via network

    • A.

      Yes

    • B.

      No

    Correct Answer
    A. Yes
    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.

    Rate this question:

  • 8. 

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

    • A.

      Yes

    • B.

      No

    • C.

      Does Not Matter

    Correct Answer
    A. Yes
    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.

    Rate this question:

  • 9. 

    Can excessive use of reflection incur performance cost?

    • A.

      Yes

    • B.

      No

    Correct Answer
    A. Yes
    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.

    Rate this question:

  • 10. 

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

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    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.

    Rate this question:

Quiz Review Timeline +

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
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.