Login Here                        


The process of saving an object to a file (or) the process of sending an object across the network is called serialization.
But strictly speaking the process of converting the object from java supported form to the network supported form of file supported form.
To do the serialization we required fallowing classes
  1. FileOutputStream
  2. ObjectOutputStream

To perform serialization :- we are writing the object data to the file called abc.txt file we are transferring that file across the network.

public class Student implements Serializable
int id;
String name;
int marks;
public Student(int id, String name,int marks)
{ = id; = name;

class Serializable1
public static void main(String args[])throws Exception
Student s1 =new Student(211,"ravi",100);
FileOutputStream fos=new FileOutputStream("abc.txt",true);
ObjectOutputStream oos=new ObjectOutputStream(fos);
System.out.println("Serializable process success");

intput and output

output:abc.txt write objuct

To perform deserialization:- in the network the file is available with java data to read the data we have to go for deserialization.

class Deserialization
public static void main(String args[])throws Exception
//deserialization process
FileInputStream fis=new FileInputStream("abc.txt");
ObjectInputStream ois=new ObjectInputStream(fis);
Student s=(Student)ois.readObject();
System.out.println("the student name is:";
System.out.println("the stuent id is:";
System.out.println("the student marks:"+s.marks);
System.out.println("deserialization success");

intput and output

output:get in said file data