JDBC
IO Framework
.png)
Chaining IO Streams

.png)
- Each IO stream object performs a specific task.
- FileOutputStream -- Write the given bytes into the file (on disk).
- BufferedOutputStream -- Hold multiple elements in a temporary buffer before flushing it to underlying stream/device. Improves performance.
- DataOutputStream -- Convert primitive types into sequence of bytes. Inherited from DataOutput interface.
- ObjectOutputStream -- Convert object into sequence of bytes. Inherited from ObjectOutput interface.
- PrintStream -- Convert given input into formatted output.
- Note that input streams does the counterpart of OutputStream class hierarchy.
- Streams can be chained to fulfil application requirements.
Primitive types IO
- DataInputStream & DataOutputStream -- convert primitive types from/to bytes
- primitive type --> DataOutputStream --> bytes --> FileOutputStream --> file.
- DataOutput interface provides methods for conversion - writeInt(), writeUTF(), writeDouble(), ...
- primitive type <-- DataInputStream <-- bytes <-- FileInputStream <-- file.
- DataInput interface provides methods for conversion - readInt(), readUTF(), readDouble(), ...
DataOutput/DataInput interface
interface DataOutput
writeUTF(String s)
writeInt(int i)
writeDouble(double d)
writeShort(short s)
...
interface DataInput
String readUTF()
int readInt()
double readDouble()
short readShort()
...
Serialization

.png)
.png)
- ObjectInputStream & ObjectOutputStream -- convert java object from/to bytes
- Java object --> ObjectOutputStream --> bytes --> FileOutputStream --> file.
- ObjectOutput interface provides method for conversion - writeObject().
- Java object <-- ObjectInputStream <-- bytes <-- FileInputStream <-- file.
- ObjectInput interface provides methods for conversion - readObject().
- Converting state of object into a sequence of bytes is referred as Serialization. The sequence of bytes includes object data as well as metadata.
- Serialized data can be further saved into a file (using FileOutputStream) or sent over the network (Marshalling process).
- Converting (serialized) bytes back to the Java object is referred as Deserialization.