DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
WORKSHEET 3
Student Name: Chinmay Rathore UID: 22BCS12304
Branch: CSE Section/Group: 702/B
Semester: 3rd Date of Performance: 20/10/23
Subject Name: Java Programming Subject Code: 22CSH-201
1. Aim: Define a person class that implement serializable the person
class has a name, age and contact attributes in main create a person
object cast the object back to person family, deserialized person
information.
2. Source Code:
import [Link].*;
class Person implements Serializable {
private String name;
private int age;
private String contact;
public Person(String name, int age, String contact) {
[Link] = name;
[Link] = age;
[Link] = contact;
}
public String getName() {
return name;
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
public int getAge() {
return age;
}
public String getContact() {
return contact;
}
}
public class Main {
public static void main(String[] args) {
Person person = new Person("Avinash", 20,
"avinash@[Link]");
try {
FileOutputStream fileOut = new
FileOutputStream("[Link]");
ObjectOutputStream out = new
ObjectOutputStream(fileOut);
[Link](person);
[Link]();
[Link]();
[Link]("Person object serialized and
saved to [Link]");
} catch (IOException e) {
[Link]();
}
Person deserializedPerson = null;
try {
FileInputStream fileIn = new
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
FileInputStream("[Link]");
ObjectInputStream in = new
ObjectInputStream(fileIn);
deserializedPerson = (Person) [Link]();
[Link]();
[Link]();
} catch (IOException | ClassNotFoundException e) {
[Link]();
}
if (deserializedPerson != null) {
[Link]("Deserialized" +
" Person Information:");
[Link]("Name: " +
[Link]());
[Link]("Age: " +
[Link]());
[Link]("Contact: " +
[Link]());
}
}
}
3. Screenshot of Outputs:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
4. Learning Outcomes
(i) Understand the concept of Java programming.
(ii) Developed problem-solving skills.