Exam Questions and CORRECT Answers
1. Streams that input bytes from and output bytes to files are known as ________.
a. bit-based streams
b. byte-based streams
c. character-based streams
d. Unicode-based streams - CORRECT ANSWER - b. byte-based streams
2. Which of the following statements is false?
a. A Path represents the location of a file or directory.
b. Path objects open files and provide file-processing capabilities.
c. Class Paths is used to get a Path object representing a file or directory location.
d. The static method get of class Paths converts a String representing a file's or directory's
location into a Path object - CORRECT ANSWER - b. Path objects open files and provide
file-processing capabilities.
3. A(n) ________ path starts from the directory in which the application began executing.
a. absolute
b. relative
c. parallel
d. comparative - CORRECT ANSWER - b. relative
4. Path method ________ returns the String name of a file or directory without any location
information.
a. getStringName
b. getFileOrDirectoryName
c. getDirectoryName
d. getFileName - CORRECT ANSWER - d. getFileName
,5. Files static method ________ receives a Path and returns a boolean indicating whether that
Path represents a directory on disk.
a. isDiskDirectory
b. isDirectory
c. isFileDirectory
d. isPath - CORRECT ANSWER - b. isDirectory
6. What does the following statement do?
Scanner scanner = new Scanner(Paths.get("test.txt")); - CORRECT ANSWER - c. Opens a
text file for input.
7. String objects are immutable. This means they ________. - CORRECT ANSWER - c.
cannot be changed
8. The length of a string can be determined by ________.
a. the String method length()
b. the String instance variable length
c. the String method strlen()
d. All of the above. - CORRECT ANSWER - a. the String method length()
9. The statement
s1.equalsIgnoreCase(s4)
is equivalent to which of the following?
a. s1.regionMatches(true, 0, s4, 0, s4.length());
b. s1.regionMatches(0, s4, 0, s4.length());
c. s1.regionMatches(0, s4, 0, s4.length);
d. s1.regionMatches(true, s4, 0, s4.length); - CORRECT ANSWER - a.
s1.regionMatches(true, 0, s4, 0, s4.length());
, 10. The statement
s1.startsWith("art")
has the same result as which of the following?
a. s1.regionMatches(0, "art", 0, 3);
b. s2 = s1.getChars(0, 3);
s2.equals("art");
c. s1.regionMatches(true, 0, "art", 0, 3);
d. All of the above - CORRECT ANSWER - d. All of the above
11. For
String c = "hello world";
The Java statements
int i = c.indexOf('o');
int j = c.lastIndexOf('l');
will result in: - CORRECT ANSWER - c. i = 4 and j = 9.
12. Given the following declaration:
StringBuilder buf = new StringBuilder();
What is the capacity of buf?
a. 0
b. 10
c. 16
d. 20 - CORRECT ANSWER - c. 16
13. Given the following declarations:
StringBuilder buffer = new StringBuilder("Testing Testing");
buffer.setLength(7);