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. 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. 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.
5. Byte streams are defined by using two class hierarchies.
1. Inputstream
2. Outputstream
Provides convenient means for handling input and
output of bytes.
7. 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.
8. 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.
9. 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-----
}
10. Classes used for Reading and writing objects
The ObjectInputStream class
The ObjectOutputStream class
The Classes are found
in
java.io package
11. 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
12.
13.
14.
15.
16. 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
}
17. 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.