forked from learning-zone/java-basics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransientKeyword.java
More file actions
30 lines (24 loc) · 881 Bytes
/
TransientKeyword.java
File metadata and controls
30 lines (24 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package keywords;
import java.io.*;
public class TransientKeyword implements Serializable {
int i = 10, j = 20;
transient int k = 30;
transient static int l = 40;
transient final int m = 50;
public static void main(String[] args) throws Exception {
TransientKeyword input = new TransientKeyword();
//Serialization
FileOutputStream fos = new FileOutputStream("file.txt");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(input);
//deserialization
FileInputStream fis = new FileInputStream("file.txt");
ObjectInputStream ois = new ObjectInputStream(fis);
TransientKeyword output = (TransientKeyword)ois.readObject();
System.out.println("i = " + output.i);
System.out.println("j = " + output.j);
System.out.println("k = " + output.k);
System.out.println("l = " + output.l);
System.out.println("m = " + output.m);
}
}