Commentary below slide.
|
|
Slide 15 of 111
Notes:
The copy of the 'a' character that was echoed to the video console appears on the screen. The original 'a' character that traveled down the keyboard stream is sitting at the junction. The CPU is still executing the ReadByte program below. The statement in the program the CPU is executing is still code = System.in.read(). So, the computer is still evaluating System.in.read(). The program is unaware that an 'a' key was ever pressed, even though a copy of the 'a' is now displayed on the video console.
public class ReadByte {
public static void main(String args[]) {
char ch;
int code;
try {
code = System.in.read();
} catch (Exception e) {
System.out.println("Error found.");
return;
}
ch = (char) code;
System.out.println("Read: " + ch);
}
}