Question: 1. Which line completes this code fragment to define a text file named txtfile for reading? ____________________________________________________ String line = scan.nextLine(); Reader scan = new
1. Which line completes this code fragment to define a text file named txtfile for reading?
____________________________________________________
String line = scan.nextLine();
| Reader scan = new Reader(new File("txtfile")); | ||
| FileReader scan = new File("txtfile"); | ||
| Scanner scan = new Scanner(System.in); | ||
| Scanner scan = new Scanner(new File("txtfile")); |
1 points
QUESTION 2
Why does FileInputStream override the read method from its superclass InputStream?
| In order to return a char. | ||
| In order to read binary data. | ||
| To read data from a file. | ||
| To check for end of file. |
1 points
QUESTION 3
If we read a byte and the value represents an international character equal to 133 using an InputStream object, what is true about the int value we will read?
| It will be 133. | ||
| It will be -133. | ||
| It will be some negative value. | ||
| It will be some positive value. |
1 points
QUESTION 4
Caesar cipher uses a shift of each character by a key with a value between 1 and 255. An a with a shift equal to 3 becomes a d. A z would become a c, wrapping around the alphabet.Which is the decryption of exmmv for a key = -3?
| cvkkt | ||
| atiir | ||
| bujjs | ||
| happy |
1 points
QUESTION 5
Which of these classes access sequences of characters?
I readers
II writers
III streams
| I | ||
| II | ||
| I and II | ||
| II and III |
1 points
QUESTION 6
Which of the following cannot be serialized?
I ArrayList
II String
III Integer
| I | ||
| II and III | ||
| III | ||
| All can be serialized |
1 points
QUESTION 7
In which of the following modes can a RandomAccessFiles be opened?
I r
II rw
III w
| I | ||
| II | ||
| I and II | ||
| I and III |
1 points
QUESTION 8
In Java, you use a(n) ____________ object to access a file and move its file pointer.
| Stream | ||
| Serializable | ||
| SequentialAccessFile | ||
| RandomAccessFile |
1 points
QUESTION 9
Caesar cipher uses a shift of each character by a key with a value between 1 and 255. An a with a shift equal to 3 becomes a d. For the encrypt method below, select the correct body. Assume the key shift property is accessible to the method.
public int encrypt(int b) { __________ }
| return (b + key); | ||
| return (b + key % 26); | ||
| return (b + key) % 256); | ||
| return (b + 26 % key); |
1 points
QUESTION 10
What type is returned from a call to the ObjectInputStream.readObject method when reading a String from an object stream?
| Object | ||
| String | ||
| char | ||
| ObjectStream |
1 points
QUESTION 11
How many methods are required to implement the Serializable interface?
| 3 | ||
| 2 | ||
| 1 | ||
| 0 |
1 points
QUESTION 12
Which class is used for input of text data from a file?
| RandomAccessFile | ||
| FileWriter | ||
| FileInputStream | ||
| Scanner |
1 points
QUESTION 13
How many bytes does the read method in the FileInputStream class actually get from the file?
| 1 | ||
| 2 | ||
| 4 | ||
| 8 |
1 points
QUESTION 14
Which is not a method in the RandomAccessFile class?
| getFilePointer | ||
| seek | ||
| scan | ||
| length |
1 points
QUESTION 15
A file pointer is a position in a random access file. Because files can be very large,
the file pointer is of type _______.
| double | ||
| byte | ||
| int | ||
| long |
1 points
QUESTION 16
The read method of the FileInputStream class reads binary data. What type is actually returned from a call to read?
| int | ||
| char | ||
| String | ||
| byte |
1 points
QUESTION 17
If we want to write objects to a file, what type of object should be passed to the ObjectOutputStream constructor?
| ObjectStream | ||
| FileStream | ||
| FileOutputStream | ||
| ObjectInputStream |
1 points
QUESTION 18
Which of the following statements enables you to write output to a text file?
| PrintWriter out = new PrintWriter(); | ||
| PrintWriter out = new PrintWriter("output.txt"); | ||
| FileReader reader = new FileReader("input.txt"); | ||
| Scanner in = new Scanner(reader); |
1 points
QUESTION 19
You use _________ and FileOutputStream objects to write data to a disk file in text or binary form respectively.
| FileReader | ||
| PrintWriter | ||
| OutputStreamWriter | ||
| ObjectOutputStream |
1 points
QUESTION 20
Streams access sequences of ____.
| characters | ||
| files | ||
| strings | ||
| bytes |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
