i have made a serialized class,like this
`
class Example implements Serializable
{
transient byte i=2;
transient byte j=3;
Example(){System.out.println("value of i:"+i+",j:"+j);}
}
`
when i am serilizing n deserializing the class,i.e.
class SerialClass
{
public static void main(String []r)//throws IOException
{
try{
System.out.println("Serialization");
Example e=new Example();
FileOutputStream out=new FileOutputStream("hyxa_code.txt");
/*File f=new File("copt.txt");
f.createNewFile();*/
ObjectOutputStream oo=new ObjectOutputStream(out);
oo.writeObject(e);
oo.close();}catch(IOException e){}
try{
System.out.println("Deserialization");
Example ee=new Example();
FileInputStream in=new FileInputStream("hyxa_code.txt");
ObjectInputStream o=new ObjectInputStream(in);
ee=(Example)o.readObject();
System.out.println("The vlaue of i,j:"+ee.i+" "+ee.j);
}catch(IOException e)
{}
catch(ClassNotFoundException e){}
}
}
the output is coming like this:
Serialization
value of i:2,j:3
Deserialization
value of i:2,j:3
The vlaue of i,j:0 0
but as i have heard, Deserialization doesn't initialize constructor, here is happening,why??? also,why the value of both variables is coming as it was initialized