Java Reference
In-Depth Information
character input. Input devices, such as a keyboard, typically are much slower
than the computer's CPU; buffering the data reduces the number of times the
CPU has to interact with the device to obtain the input data.
Recall that an instance is a unique object or a specific occurrence of a class
of objects. Instantiation is the process of constructing an instance of a data type
or object from a previously defined class. As discussed in Chapter 2, you use a
special method called a constructor to create an instance of a class of objects. All
Java classes have constructors that are used to initialize a new object of that type;
the constructor method has the same name as the class.
Line 20 in Figure 3-11 calls a constructor to instantiate , or declare an
instance of, the BufferedReader class. The resulting line of Java code may seem a
bit cryptic; Table 3-5 breaks down and explains the purpose of the constructor
code to declare the BufferedReader class.
20
BufferedReader dataIn= new BufferedReader ( new
InputStreamReader ( System .in )) ;
21
FIGURE 3-11
Table 3-5 The BufferedReader Constructor Code
CODE COMPONENTS
TERMINOLOGY
EXPLANATION
BufferedReader
a class from the java.io package
A class that reads text from a character input
stream, buffering characters so as to provide for the
efficient reading of characters, arrays, and lines.
dataIn
identifier (variable) to hold the
Variable name assigned by the programmer.
inputted data
= new
constructor notation
The standard notation to instantiate or construct an
instance of a class.
BufferedReader()
method
A constructor or method used to instantiate or
construct an instance of the BufferedReader class.
InputStreamReader()
a class from the java.io package
An InputStreamReader is a bridge from byte streams
to character streams; it reads bytes and decodes
them into characters. It usually is wrapped inside a
BufferedReader.
System.in
an object representing input
An object representing the standard input device
from a buffer
on a computer system, usually the keyboard.
The argument of the BufferedReader() method, on the right side of the
constructor notation, instantiates a new InputStreamReader class. The
InputStreamReader acts as a bridge to read the stream of bytes from the
keyboard buffer and decode the bytes into characters. The BufferedReader()
method returns a reference to the input data from the System.in.
 
Search WWH ::




Custom Search