Serialization:
the process of writing state of an object to a file is called serialization. But strictly speaking it is the process of converting an object from java supported form to either file supported form or network supported form.
By using FileOutputStrem and ObjectOutPutStream classes we can implement Serialization.
fig
Desirialization:
The process of reading state of an object from a file is called desirialization But strictly speaking it is the proccess of converting an object from either bytesupported or network supported form to java supported form.
By using FileInputStream and ObjectInputStream classes we can achieve deserialization.
FIG
Ex: import java.io.*;
class Dog implements Serialize
{
i=10;
h=20;
}
class SerializeDemo
{
main()
{
Dog d=new Dog();
//serialization
FileOutPutStream fos=new FileOutputStream("abc.ser");
ObjectOutputStream oos=new ObjectOutputStream(fos);
oos.writeObject(d);
//Deserialization
FileInputStream fis=new FileInputStream("abc.ser");
ObjectInputStream ois=new ObjectInputStream(fis);
Dog d1=(Dog)ois.readObject();
sop(d1.i+"\t"+d1.j);
}
}
FIG:
we can seriallize only serializable objects. An object is said to be serializale iff the corresponding class implements serializable interface.
serializable interface present in the java.io package and doesn't contain any methods. it is a marker interface if we are trying to serialize a non serializable object then we will get Runtime exception saying net
- Introduction
- Object graphs in serialization
- customized serialization
- serialization w.r.t inheritance
- externalization
the process of writing state of an object to a file is called serialization. But strictly speaking it is the process of converting an object from java supported form to either file supported form or network supported form.
By using FileOutputStrem and ObjectOutPutStream classes we can implement Serialization.
fig
Desirialization:
The process of reading state of an object from a file is called desirialization But strictly speaking it is the proccess of converting an object from either bytesupported or network supported form to java supported form.
By using FileInputStream and ObjectInputStream classes we can achieve deserialization.
FIG
Ex: import java.io.*;
class Dog implements Serialize
{
i=10;
h=20;
}
class SerializeDemo
{
main()
{
Dog d=new Dog();
//serialization
FileOutPutStream fos=new FileOutputStream("abc.ser");
ObjectOutputStream oos=new ObjectOutputStream(fos);
oos.writeObject(d);
//Deserialization
FileInputStream fis=new FileInputStream("abc.ser");
ObjectInputStream ois=new ObjectInputStream(fis);
Dog d1=(Dog)ois.readObject();
sop(d1.i+"\t"+d1.j);
}
}
FIG:
we can seriallize only serializable objects. An object is said to be serializale iff the corresponding class implements serializable interface.
serializable interface present in the java.io package and doesn't contain any methods. it is a marker interface if we are trying to serialize a non serializable object then we will get Runtime exception saying net
Comments
Post a Comment