Serialization is a mechanism of converting the state of an object into a byte stream. Deserialization is the reverse process where the byte stream is used to recreate the actual Java object in memory. This mechanism is used to persist the object.

java.io.Serializable interface

The next example show how to apply this in object class :

import java.io.Serializable;  
public class Person implements Serializable{  
 int id;  
 String name;  
 public Person(int id, String name) {  
  this.id = id;  
  this.name = name;  
 }  
}  

Laisser un commentaire