Section 3a

The Data Stream Concept


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Program Input and Output

The Data Stream Concept

While programs can be loaded and run on a computer, they don’t do much if they don’t have data to work with. So, from almost the beginning of commercial computer development, a “data stream” metaphor has been used to both manage and understand the flow of data into and out of a program.

The data stream is considered to be one path within the computer to which various devices can be connected. Originally, these devices were tape drives, and then punch cards and keyboards, and then printers and monitors. The great thing about this concept however, is that it has adapted seamlessly to USB memory sticks, CD and DVD drives, various network interfaces, and so on. The concept works and continues to help us understand the flow of data.

The two devices you will use at first are considered to be the default I/O or input and output devices. That is to say, they are the ones to be used if no other options are chosen. You will use the keyboard, which is considered to be the “Console In” device, and you will use the monitor, which is considered to be the “Console Out” device.

Consider the code example below that is prompting for, and acquiring data from a user, at the console:

resultString = JOptionPane.showInputDialog( "Enter your age: " );

Now consider the code again, as if the data stream were connected to your code.

resultString = JOptionPane.showInputDialog( "Enter your age: " );

Image of output data stream

 

 

 

 

 

 

 

 

 

 

 

The JOptionPane.showInputDialog process is effectively attached to the data stream so that whatever is output is put in the data stream and finds its way to the console out device (i.e., the monitor).

Now consider the response that acquires the age value from the user and places it in the age variable.

Image showing extraction from data stream

resultString = JOptionPane.showInputDialog( "Enter your age: " );

The output of JOptionPane.showInputDialog process, which comes from the user through the keyboard, is placed into the data stream and delivered through to your program.

This is not a terribly difficult concept to learn about, but it is important for students to know that one data chunk (commonly a byte) is passed into this stream, and data comes back out as a data chunk. As long as you will remember that data stream metaphor, Input and Output (I/O) will always make sense to you.