What is Serialization ?
Serialization is a mechanism in which Object can represent as a sequence of bytes that include
the object data.
Download Complete Project For Here
for Serialization we need Implement Serializable Interface
------------------------------------------------------------------
----------------------------------------------------------------
Serialization is a mechanism in which Object can represent as a sequence of bytes that include
the object data.
Download Complete Project For Here
for Serialization we need Implement Serializable Interface
------------------------------------------------------------------
----------------------------------------------------------------
package com.netroxtech.serial;
import java.io.Serializable;
public class Student implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private int id;
private String name=null;
private String email=null;
private String Program=null;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getProgram() {
return Program;
}
public void setProgram(String program) {
Program = program;
}
}
-------------------------------------------------------------------
-------------------------------------------------------------------
package com.netroxtech.main;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import com.netroxtech.serial.Student;
public class Deserialization {
public Deserialization()
{
Student s=null;
try{
FileInputStream file=new FileInputStream("D:\\Student.ser");
ObjectInputStream in=new ObjectInputStream(file);
s=(Student)in.readObject();
System.out.println("-------After DeSerialzation.........");
System.out.println("Student ID: "+s.getId());
System.out.println("Student Name: "+s.getName());
System.out.println("Student Name: "+s.getProgram());
System.out.println("Student Name: "+s.getEmail());
}
catch(Exception e){
e.printStackTrace();
}
}
}
----------------------------------------------------------------------------------
---------------------------------------------------------------------------------
package com.netroxtech.main;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import com.netroxtech.serial.Student;
public class Serialization {
public static void main(String []args){
Student s=new Student();
s.setId(1);
s.setEmail("@gmail.com");
s.setName("Abdullah Masood");
s.setProgram("BS:SE");
try{
FileOutputStream file=new FileOutputStream("D:\\Student.ser");
ObjectOutputStream output=new ObjectOutputStream(file);
output.writeObject(s);
System.out.println("Object Successfully Write");
file.close();
output.close();
/*
* This Call Deserialization default Constructor
*
*/
Deserialization d=new Deserialization();
}
catch(IOException e){
e.printStackTrace();
}
}
}