Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Object Oriented Programming - Java Serialization: Serialization involves saving the current state of an object to a stream, and restoring an equivalent object from that

Object Oriented Programming - Java

image text in transcribed

Serialization: Serialization involves saving the current state of an object to a stream, and restoring an equivalent object from that stream. The stream functions as a container for the object. Its contents include a partial representation of the object's internal structure, including variable types, names, and values. The information stored in the container can later be used to construct an equivalent object containing the same data as the original. For an object to be serialized, it must be an instance of a class that implements either the Serializable or Externalizable interface. Both interfaces only permit the saving of data associated with an object's variables. They depend on the class definition being available to the Java Virtual Machine at reconstruction time in order to construct the object. The Serializable interface relies on the Java runtime default mechanism to save an object's state. Writing an object is done via the writeObject() method in the ObjectOutputStream class (or the ObjectOutput interface). Writing a primitive value may be done through the appropriate write() method. Reading the serialized object is accomplished using the readObject() method of the objectInputStream class, and primitives may be read using the various read() methods. Write a program that serializes a array list in a binary file, reads it from the binary file and writes it to the text area. Create the following classes: DIS: + doctors: ArrayList Doctor: serializable -id: String -name: String -surname: String -department: String +Doctor (id name.surname dept) +toString(): String + AddToArrayList (Doctor e): void + WriteArrayListtobin (): void + DisplayBin(): String Doctors Doctor ID: Add to ArrayList Name: Write ArrayList To Bin Display the Binary You have 5 labels, 3 buttons, 4 text fields, 1 scroll pane and 1 text area over it. "Add to arraylist" button will create an object of doctor and add to an arraylist type Doctor by calling the AddToArrayList() method. "Write ArrayList to Bin" button will write the Arraylist into a binary file named Doctor_bin by calling WriteArrayListtoBin() method: objo = new ObjectOutputStream (new FileOutputStream("Doctor_bin")); Surname: Department: Display Doctor doctor_id=111 doctor_name=Ceren, doctor_sur-Ser department=Dahiliye Doctor doctor id.222 "Display the Binary" button will read the data from the binary file and display it to the text area by calling DisplayBin) method: ObjectInputStream obji = new ObjectInputStream (new FileInputStream("Doctor_bin")); ArrayList stemp=(ArrayList>(obji.readobject())

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Principles Programming And Performance

Authors: Patrick O'Neil

1st Edition

1558603921, 978-1558603929

More Books

Students also viewed these Databases questions