KIRAN V KULKARNI
ROLL NO: 28 DIV: A
MCA IV SEMESTER
ROLL NO: 40 DIV: A
MCA IV SEMESTER
It is an abstraction that either produces or consumes
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.
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
java.io package contains all the classes required for
input and output operations.
Byte streams are defined by using two class hierarchies.
Provides convenient means for handling input and
output of bytes.
Character streams are defined by using two class
Character streams provide a convenient means for
handling input and output of characters.
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.
How to serialize Objects in Java
Any object whose class implements the java.io.Serializable interface can
be made persistent
public class UserData implements Serializable
Classes used for Reading and writing objects
The ObjectInputStream class
The ObjectOutputStream class
The Classes are found
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
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
Variables that are part of the persistent state of an object must be
saved when the object is archived
class MyData implements Serializable
transient int age;
---constructor to enterdata
• 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
• Transient Variables are not persisted.