Java Reference
In-Depth Information
Certification Practice
The following question is the kind of thing you could expect to be asked on a Java pro-
gramming certification test. Answer it without looking at today's material or using the
Java compiler to test the code.
Given:
import java.io.*;
public class Unknown {
public static void main(String[] arguments) {
String command = “”;
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
try {
command = br.readLine();
}
catch (IOException e) { }
}
}
Will this program successfully store a line of console input in the String object named
command ?
a. Yes.
b. No, because a buffered input stream is required to read console input.
c. No, because it won't compile successfully.
d. No, because it reads more than one line of console input.
The answer is available on the topic's website at http://www.java21days.com. Visit the
Day 15 page and click the Certification Practice link.
Exercises
To extend your knowledge of the subjects covered today, try the following exercises:
1. Write a modified version of the HexRead program from Day 7, “Exceptions,
Assertions, and Threads,” that reads two-digit hexadecimal sequences from a text
file and displays their decimal equivalents.
2. Write a program that reads a file to determine the number of bytes it contains and
then overwrites all those bytes with zeroes ( 0 ). (For obvious reasons, don't test this
program on any file you intend to keep; the data in the file will be wiped out.)
Where applicable, exercise solutions are offered on the topic's website at http://www.
java21days.com.
 
Search WWH ::




Custom Search