forked from sarjus/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSerializeDemo.java
More file actions
40 lines (40 loc) · 1.36 KB
/
SerializeDemo.java
File metadata and controls
40 lines (40 loc) · 1.36 KB
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
31
32
33
34
35
36
37
38
39
40
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
class Employee implements java.io.Serializable {
public String name;
public String address;
public int SSN;//This value will not be copied
public transient int extentionNumber;
Employee(String name, String address, int SSN, int extentionNumber ){
this.name = name;
this.address = address;
this.SSN = SSN;
this.extentionNumber = extentionNumber;
}
public void getEmployeeDetails() {
System.out.println("Deserialized Employee...");
System.out.println("Name: " + name);
System.out.println("Address: " + address);
System.out.println("SSN: " + SSN);
System.out.println("Number: " + extentionNumber);
}
}
public class SerializeDemo {
public static void main(String[] args) {
Employee e = new Employee("Joe", "House No:13, Pala, Kottayam",546178,110);
Employee e1 = new Employee("Sarju", "SJCET", 12458, 312);
try {
FileOutputStream fileOut =
new FileOutputStream("employee.ser");
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(e);
out.writeObject(e1);
out.close();
fileOut.close();
System.out.printf("Serialized data is saved in employee.ser");
} catch (IOException i) {
i.printStackTrace();
}
}
}