1. Which line completes this code fragment to define a text file named txtfile f
ID: 3822881 • Letter: 1
Question
1. Which line completes this code fragment to define a text file named txtfile for reading?
____________________________________________________
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<String>
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
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"));
Explanation / Answer
Answer:
1. Scanner scan = new Scanner(System.in);
The above line completes the code to define a textfile.
2. To read data from a file.
it overrides to implement all the methods in the program.
3.
4. bujjs
using caesar cipher,
e->b, x-u, m->j, v->s
Hence, bujjs.
5. I and II
Readers and writers classes access sequence of characters.
6. All can be serialized
Yes, serialization not only stores the object, but also the states of the object.
7. I and II
The mode argument can be either "r" for read only or "rw" can be read and written to.
8. RandomAccessFile
random access files, you can acess the files directly and quickly without searching through all the other records first.
9. return (b + key) % 256);
10. ObjectStream
11. 0
12. FileWriter
FileWriter is used for input of text data from a file.
18. PrintWriter out = new PrintWriter("output.txt");
19. PrintWriter
20. Characters
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.