Youtube Channel

Searialization in Java with tranient variable

package com.pack.serialization;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

public class BasicSerial implements Serializable {
    int a=10;
    int b=20;
    int c=30;
    String str="kamlesh mishra";
    String college="itm university";
    final transient int d=50;

    public static void main(String[] args)throws Exception {

        BasicSerial bs=new BasicSerial();
        FileOutputStream fos=new FileOutputStream("d:\\kkm.txt");
        ObjectOutputStream oos=new ObjectOutputStream(fos);
        oos.writeObject(bs);
        FileInputStream fis=new FileInputStream("d:\\kkm.txt");
        ObjectInputStream ois=new ObjectInputStream(fis);
        BasicSerial ro=(BasicSerial)ois.readObject();
        System.out.println(ro.d);
    }

}
Next PostNewer Post Previous PostOlder Post Home

0 comments: