How do we make a class serialize?

Answer Posted / javamasque

We have to fallow below steps to serialize an object
1. The object to be serialized need to implement java.io.Serializable interface.
2. It will use Java’s default serialization mechanism.
3. Generate serial version id for that serializable object.
4. Only default constructor is applicable to all class hierarchy (from child to all super classes if any). It is necessary at deserialization otherwise throw InvalidClassException.
5. Generate serial version UID for all super classes in hierarchy (all super classes if any) otherwise the properties of all its super classes will be assigned to its default value during deserializtion.
6. ObjectOutputStream is used to write [writeObject] object.
7. FileOutputStream is used to persist in flat file.
8. The flat file extension should be (<file-name>.ser)

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the maximum size of a string in java?

551


What is the size of boolean variable?

577


Difference between arraylist and vector.

594


What is factor r?

529


What is pass by value?

513






What is lifetime variable?

525


Can you run java program without main method?

545


In how many ways we can do synchronization in java?

529


Write a program to check string is palindrome without using loop?

568


Can an integer be a string?

513


What is the exception hierarchy in java?

488


What are multiple inheritances?

585


How does multithreading take place on a computer with a single cpu?

545


Write a function for palindrome and factorial and explain?

661


What are the legal operands of the instanceof operator?

566