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 are basic data types?

554


Why parsing is done?

498


What is assembly condition codes?

556


Is char a data type in java?

537


What is the difference between class & structure?

559






How many arguments can be passed to main ()?

518


Explain about the interpreter in java?

619


What does localhost mean?

490


How does hashset works in java?

526


Do I need java on my pc?

506


How do generics work?

514


Where is core java used?

574


How to find the largest value from the given array.

520


How do you sort in ascending order in java?

516


Give the hierarchy of inputstream and outputstream classes.

606