Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Java I/O and Object Serialization

181 views

Published on

Java Input Output and Object Serialization

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Java I/O and Object Serialization

  1. 1. JAVA I/O KIRAN V KULKARNI ROLL NO: 28 DIV: A MCA IV SEMESTER NAVNEET PRAKASH ROLL NO: 40 DIV: A MCA IV SEMESTER
  2. 2.  It is an abstraction that either produces or consumes information.  Stream is linked to a physical device by the Java I/O system.  A stream is a sequence of data.  Stream is composed of bytes.  It's called a stream because it's like a stream of water that continues to flow.
  3. 3.  Java implements streams within class hierarchies defined in the java.io package.  Input and Output (I/O) is used to process the input and produce the output based on the input.  Java uses the concept of stream to make I/O operations fast.  java.io package contains all the classes required for input and output operations.
  4. 4.  Byte streams are defined by using two class hierarchies. 1. Inputstream 2. Outputstream  Provides convenient means for handling input and output of bytes.
  5. 5. System Class Meaning
  6. 6.  Character streams are defined by using two class hierarchies. 1. Reader 2. Writer  Character streams provide a convenient means for handling input and output of characters.
  7. 7. Object Serialization  Serializing objects is the process of writing objects to a file.  When an object is serialized, its state and other attributes are converted into an ordered series of bytes.  This byte series can be written into streams.
  8. 8. How to serialize Objects in Java  Any object whose class implements the java.io.Serializable interface can be made persistent import java.io.*; public class UserData implements Serializable { -----member data------ -----member methods----- }
  9. 9. Classes used for Reading and writing objects  The ObjectInputStream class  The ObjectOutputStream class The Classes are found in java.io package
  10. 10. ObjectOutputStream Methods  public void writeObject(Object obj)  Write the specified object to the ObjectOutputStream.  public void WriteUTF(String str)  Primitive data write of this String in UTF format.  public void flush()  Flushes the stream  public void close()  Closes the stream
  11. 11. Introduction to Transient variables  You use the transient keyword to indicate to the Java virtual machine that the indicated variable is not part of the persistent state of the object.  Variables that are part of the persistent state of an object must be saved when the object is archived class MyData implements Serializable {String name; transient int age; ---constructor to enterdata }
  12. 12. Summary (Contd.) • Serialization allows reducing time taken to write code for save and restoration of object or application state • Serialization makes it easier for objects to travel over a network connection. • Transient Variables are not persisted.

×