Linkbar

>> Saturday, April 16, 2011

"Serialization is the process of converting the data(Objects) into stream of bytes and storing in to the files or database."

We can do the Serialization process by implementingSerializable interface.

class SerialDemo implements java.io.Serializable.

The above step tells the compiler that you are going to implement serialization.
Which basically means that the object is going to be saved or persisted.
use FileOutputStream class and ObjectOutputStream class.

FileOutuptStream Creates an output file stream to write to the file with the specified name. A new FileDescriptor object is created to represent this file connection.

An ObjectOutputStream writes primitive data types and graphs of Java objects to an OutputStream. The objects can be write using an ObjectOutputStream.

Save the file using

writeObject(obj);

Program for Serialization

What if you have something top secret, like your password which should not be saved. You mark it as transient!