Types of Streams

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page        

Answer:

Image files, audio files, executable files from other programming languages, many kinds of data files, ... the list is endless.

Types of Streams

A stream object may be:

  • An input stream or an output stream,
  • a processing stream or an ordinary stream,
  • a character-oriented stream or a byte-oriented stream,
  • and may be connected to a variety of sources or destinations.

There are many types of streams. For example, a stream might be an "input, character-oriented, processing stream". Another stream might be an "byte-oriented output stream". Not only are there many types of streams, there are many ways to connect them together. The IO aspects of a program may take as much work as all the rest of the program!

This situation is common to all production (industrial strength) programming languages. IO is a big topic because of the wide variety of IO devices and the wide variety of data formats. A production language must be able to read data from sources written by any language running on any type of computer. For example, a program might need to read data from magnetic tapes written 30 years ago by a COBOL program running on an IBM mainframe. (You would likely use byte-oriented streams for this).

The good news is that the data formats that Java uses are the same for all computers. If a Java program running on a Macintosh writes a text file, that file can easily be read by a Java program running on a PC or on any other computer.

This is not true of most other languages. A "C" program running on one type of computer is unlikely to create a file that can easily be read by a "C" program running on another type of computer. Worse than that, two different "C" compilers for the same computer are free to use different data formats!

QUESTION 6:

A C++ program running on a IBM mainframe has written a file of integer data. Do you think that a C++ program running on a PC can read this file without trouble?