Java Reference
In-Depth Information
Chapter 5
Performing Input and Output
Input and Output
So far you have learned about classification, storage, and initialization of
data. These operations are internal to the program and, therefore, rela-
tively independent from the machine's hardware. The designers of Java de-
fined data types and data-manipulation instructions in a way that ensured
that they could be implemented with relative ease, in any modern com-
puter. This is not easy to achieve with data input and output operations. In-
put and output requires the intervention of hardware devices, such as the
keyboard, the mouse, the video system, or the printer. This makes data in-
put and output functions device-dependent and very difficult to define and
implementinalanguage,suchasJava,whichaimsatdevice-independence.
The result is that input and output operations in Java are often considered
difficult and complicated.
In this chapter, we describe a Java class named Keyin that we devel-
oped so as to simplify coding keyboard input operations. The elements of
the Keyin class are explained in detail in Chapter 18. For the time being,
you will use the class as a blackbox that contains methods for entering
numbers, characters, and strings from the keyboard. Data output to the
video display is supported by the Java libraries, although in a rather elab-
orate way.
Data Input
There is no single instruction or library method in the Java language to per-
form keyboard input. This is also true of C and C++; however, C and C++
containinputfunctionsthatarepartoftheirstandardlibraries.Not inJava,
inwhichinputtakesplaceatthedatastreamlevel.Thismeansthattoinput
Search WWH ::




Custom Search