WDD_lec_22 - Object Serialization Explanation + Example of...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
Jul 1, 2010 Object Serialization Explanation + Example of file + network Lec 22
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Serialization You want to send an object to a stream Motivation A lot of code involves boring conversion from a file to memory AddressBook program reads data from file and then parses it This is a common problem! ali, defence, 9201342 usman, gulberg, 5162346 address.txt
Background image of page 2
3 Serialization Java’s answer: Serialization Object know how to read/write themselves to streams Problem - Objects have state in memory Serialization is also called Flattening, Streaming, Dehydrate (rehydrate = read), Archiving
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Animation After serialized, passed through a stream (pipe) and reconstructed on the other side
Background image of page 4
5 Java: Automatic Serialization Serializable Interface By implementing this interface a class declares that it is willing to be read/ written by automatic serialization machinery Found in java.io package Tagging interface – has no methods and serves only to identify the semantics of being serializable Automatic Writing System knows how to recursively write out the state of an object to stream Recursively follows references and writes out those objects too! Automatic Reading s System knows how to read the data from Stream and re-create object in memory Downcasting is required
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 How it works? To write out an object of PersonInfo PersonInfo p = new PersonInfo(); ObjectOutputStream out; out.writeObject(p) To read that object back in ObjectInputStream in; PersonInfo obj = (PersonInfo) in.readObject(); Must be of the same type class and version issue
Background image of page 6
Jul 1, 2010 Example Code: Serialization Reading/Writing PersonInfo objects
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/01/2010 for the course CS CS506 taught by Professor mr. umair javed during the Spring '10 term at Virtual University of Pakistan.

Page1 / 23

WDD_lec_22 - Object Serialization Explanation + Example of...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online