Lesson 3 | Java streams |
Objective | Learn how Java uses streams to support I/O. |
Java Streams (Input/Output)
Java provides very thorough support for I/O through a rich set of classes located in the
java.io
package.
There are two types of Java streams which were defined in the Java classical Streams before Java 8 was introduced.
- input streams and
- output streams.
Most of Java's stream classes are derived from the two fundamental stream classes,
InputStream
and
OutputStream
.
How has the Java Input/Output evolved since the Java 1.0 Model?
The Java Input/Output (I/O) framework has undergone several significant changes and improvements since the Java 1.0 model. Some of the most notable changes include:
- New I/O APIs: The introduction of the java.nio package in Java 1.4 brought a new, non-blocking I/O API to the platform, which provided a more efficient and scalable way to perform I/O operations, especially for high-performance I/O-bound applications.
- Improved Character Encoding Support: The java.io and java.nio packages have been updated to provide better support for international character encoding and decoding, making it easier to work with text in a variety of languages and scripts.
- Stream-based I/O: The java.io package has been updated to use streams as a fundamental abstraction for I/O operations, providing a more flexible and consistent way to perform I/O operations.
- Channel-based I/O: The java.nio package introduced the concept of channels, which provide a way to perform I/O operations directly on the underlying device, bypassing the operating system's I/O buffers and providing a more efficient and scalable way to perform I/O operations.
- Asynchronous I/O: The java.nio.channels package introduced the concept of asynchronous I/O, which provides a way to perform I/O operations in a non-blocking manner, freeing up resources and providing a more scalable solution for I/O-bound applications.
Overall, these and other improvements have made the Java I/O framework more flexible, efficient, and scalable, enabling Java applications to better handle the challenges of I/O-bound processing.
Java 1.0. Legacy Classes I/O
These classes were introduced in Java 1.0.
In Java 1.1, a new set of I/O classes was added that is based on the Reader
and Writer
classes. These classes are functionally equivalent to InputStream
and OutputStream
, except that they support internationalization via the Unicode character set.
As of Java 2, both of these approaches to I/O are still supported. There are situations where you will need to use both sets of
classes, so it's important to understand them both. Note: Internationalization involves developing programs that can use
different character sets based on different human languages.