Deck 19: Streams and Binary Inputoutput
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/82
Play
Full screen (f)
Deck 19: Streams and Binary Inputoutput
1
Which line completes this code fragment so it creates a text file called "mychars.txt" and writes the characters 'A', 'B', and 'C' into the file?
_____________________
Fw)write('A');
Fw)write('B');
Fw)write('C');
A) PrintWriter fw = new PrintWriter("mychars.txt");
B) FileOutputStream fw = new FileOutputStream("mychars.txt");
C) File fw = new File("mychars.txt");
D) PrintStream fw = new PrintStream("mychars.txt");
_____________________
Fw)write('A');
Fw)write('B');
Fw)write('C');
A) PrintWriter fw = new PrintWriter("mychars.txt");
B) FileOutputStream fw = new FileOutputStream("mychars.txt");
C) File fw = new File("mychars.txt");
D) PrintStream fw = new PrintStream("mychars.txt");
A
2
You use _________ and FileOutputStream objects to write data to a disk file in text or binary form respectively.
A) FileReader
B) PrintWriter
C) OutputStreamWriter
D) ObjectOutputStream
A) FileReader
B) PrintWriter
C) OutputStreamWriter
D) ObjectOutputStream
B
3
The ____ class is used when writing text files.
A) PrintWriter
B) InputStream
C) JFileChooser
D) Serializable
A) PrintWriter
B) InputStream
C) JFileChooser
D) Serializable
A
4
Which class is used for input of binary data?
A) Reader
B) Writer
C) InputStream
D) OutputStream
A) Reader
B) Writer
C) InputStream
D) OutputStream
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
5
Which of the following reads binary data from a disk file?
A) PrintWriter text = new PrintWriter("input.bin");
B) FileReader text = new FileReader("input.bin");
C) FileInputStream inputStream = new FileInputStream("input.bin");
D) FileWriter text = new FileWriter("input.bin");
A) PrintWriter text = new PrintWriter("input.bin");
B) FileReader text = new FileReader("input.bin");
C) FileInputStream inputStream = new FileInputStream("input.bin");
D) FileWriter text = new FileWriter("input.bin");
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
6
Which class is used for input of text data from a file?
A) RandomAccessFile
B) FileWriter
C) FileInputStream
D) Scanner
A) RandomAccessFile
B) FileWriter
C) FileInputStream
D) Scanner
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
7
In Java, the simplest mechanism for reading text is to use the ____ class.
A) ReadWrite
B) Scanner
C) PrintWriter
D) Serializable
A) ReadWrite
B) Scanner
C) PrintWriter
D) Serializable
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
8
Which class is used for input of text data?
A) Reader
B) Writer
C) InputStream
D) OutputStream
A) Reader
B) Writer
C) InputStream
D) OutputStream
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
9
Which is an advantage of storing numbers in binary format?
I fast access
II less storage needed
III easy to read in a text editor
A) I
B) III
C) I and II
D) I and III
I fast access
II less storage needed
III easy to read in a text editor
A) I
B) III
C) I and II
D) I and III
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
10
Readers and writers access sequences of ____.
A) bytes
B) characters
C) files
D) streams
A) bytes
B) characters
C) files
D) streams
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
11
Which file storage method is in human-readable form?
A) binary
B) object
C) text
D) byte
A) binary
B) object
C) text
D) byte
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
12
Which line completes this code fragment to define a text file named txtfile for reading?
____________________________________________________
String line = scan.nextLine();
A) Reader scan = new Reader(new File("txtfile"));
B) FileReader scan = new File("txtfile");
C) Scanner scan = new Scanner(System.in);
D) Scanner scan = new Scanner(new File("txtfile"));
____________________________________________________
String line = scan.nextLine();
A) Reader scan = new Reader(new File("txtfile"));
B) FileReader scan = new File("txtfile");
C) Scanner scan = new Scanner(System.in);
D) Scanner scan = new Scanner(new File("txtfile"));
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
13
When constructing a Scanner from a File object, the Scanner automatically constructs a ___________.
A) InputStream
B) FileInputStream
C) FileReader
D) PrintWriter
A) InputStream
B) FileInputStream
C) FileReader
D) PrintWriter
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
14
If you store information in binary form, as a sequence of bytes, you will use the ____ class(es) and their subclasses.
A) InputStream and OutputStream
B) Serializable
C) PrintWriter
D) Reader and Writer
A) InputStream and OutputStream
B) Serializable
C) PrintWriter
D) Reader and Writer
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
15
In text format, data items are represented in human-readable form, as a sequence of ____________________.
A) integers
B) bytes
C) characters
D) strings
A) integers
B) bytes
C) characters
D) strings
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
16
To read text data from a disk file, you should create a(n) ____________________ object.
A) Scanner
B) PrintWriter
C) InputStream
D) OutputStream
A) Scanner
B) PrintWriter
C) InputStream
D) OutputStream
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
17
Streams access sequences of ____.
A) characters
B) files
C) strings
D) bytes
A) characters
B) files
C) strings
D) bytes
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
18
Which of the following statements enables you to write output to a text file?
A) PrintWriter out = new PrintWriter();
B) PrintWriter out = new PrintWriter("output.txt");
C) FileReader reader = new FileReader("input.txt");
D) Scanner in = new Scanner(reader);
A) PrintWriter out = new PrintWriter();
B) PrintWriter out = new PrintWriter("output.txt");
C) FileReader reader = new FileReader("input.txt");
D) Scanner in = new Scanner(reader);
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
19
Which file storage method stores data in bytes?
A) binary
B) object
C) text
D) byte
A) binary
B) object
C) text
D) byte
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
20
A byte is composed of ____ bits and can denote ____ values.
A) 2, 19
B) 4, 256
C) 8, 256
D) 8, 1024
A) 2, 19
B) 4, 256
C) 8, 256
D) 8, 1024
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
21
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?
A) It will be 133.
B) It will be -133.
C) It will be some negative value.
D) It will be some positive value.
A) It will be 133.
B) It will be -133.
C) It will be some negative value.
D) It will be some positive value.
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
22
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?
A) cvkkt
B) atiir
C) bujjs
D) happy
A) cvkkt
B) atiir
C) bujjs
D) happy
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
23
What is the highest value for a signed (negative and positive) byte?
A) 127
B) 128
C) 255
D) 256
A) 127
B) 128
C) 255
D) 256
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
24
How many bytes does the read method in the FileInputStream class actually get from the file?
A) 1
B) 2
C) 4
D) 8
A) 1
B) 2
C) 4
D) 8
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
25
How many bytes does the read method in the InputStream class get from the file?
A) 1
B) 2
C) 4
D) 8
A) 1
B) 2
C) 4
D) 8
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
26
How many bytes does the read method in the FileInputStream class actually return to the program call?
A) 1
B) 2
C) 4
D) 8
A) 1
B) 2
C) 4
D) 8
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
27
You cannot read a(n) ____________________ file with a text editor.
A) random
B) serial
C) sequential
D) binary
A) random
B) serial
C) sequential
D) binary
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
28
Which statement is true regarding the following code, assuming reader is a FileInputStream object?
Char ch = (char) reader.read();
I you cannot determine if you have reached the end of input
II this code will throw an exception if we are at the end of input
III read returns an int, so the cast is illegal
A) I
B) II
C) III
D) I and II
Char ch = (char) reader.read();
I you cannot determine if you have reached the end of input
II this code will throw an exception if we are at the end of input
III read returns an int, so the cast is illegal
A) I
B) II
C) III
D) I and II
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
29
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 key should you use to encrypt picture into mfzqrob?
A) 3
B) 19
C) -3
D) -19
A) 3
B) 19
C) -3
D) -19
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
30
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 decrypt method below, select the correct body. Assume the key shift property is accessible to the method.
Public int decrypt(int
A) return (b + key);
B) { ________ }
B) return (b - key % 26);
C) return (b - key) % 256);
D) return (b - key);
Public int decrypt(int
A) return (b + key);
B) { ________ }
B) return (b - key % 26);
C) return (b - key) % 256);
D) return (b - key);
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
31
What is the lowest value for a signed (negative and positive) byte?
A) -127
B) -128
C) -255
D) -256
A) -127
B) -128
C) -255
D) -256
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
32
What is the result of the following code?
Reader reader = … ; // connect to a file
Char ch = reader.read();
A) compiler error
B) 1 byte is read from the file
C) 2 bytes are read from the file
D) 4 bytes are read from the file
Reader reader = … ; // connect to a file
Char ch = reader.read();
A) compiler error
B) 1 byte is read from the file
C) 2 bytes are read from the file
D) 4 bytes are read from the file
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
33
If you want to process text data from a file, which keyword do you look for in classes that specialize in doing that?
A) text
B) serializable
C) binary
D) reader
A) text
B) serializable
C) binary
D) reader
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
34
The FileInputStream read method reads binary data. What type is actually returned from a call to read?
A) int
B) char
C) String
D) byte
A) int
B) char
C) String
D) byte
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
35
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 encryption of shadow for a key = 3?
A) ukdgry
B) vkdgrz
C) adowsha
D) vjegrz
A) ukdgry
B) vkdgrz
C) adowsha
D) vjegrz
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
36
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
A) return (b + key);
B) { __________ }
B) return (b + key % 26);
C) return (b + key) % 256);
D) return (b + 26 % key);
Public int encrypt(int
A) return (b + key);
B) { __________ }
B) return (b + key % 26);
C) return (b + key) % 256);
D) return (b + 26 % key);
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
37
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 encryption of picture for a key = -3?
A) erutcip
B) ngahspc
C) mfzqrob
D) urepict
A) erutcip
B) ngahspc
C) mfzqrob
D) urepict
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
38
How many bytes does the read method in the InputStream class actually return to the program call?
A) 1
B) 2
C) 4
D) 8
A) 1
B) 2
C) 4
D) 8
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
39
If you write a simple Student class, what must you do in order to write Student objects to an ObjectOutputStream?
A) Code a write method.
B) Make all class variables primitive.
C) Implement Serializable.
D) Implement Streamable.
A) Code a write method.
B) Make all class variables primitive.
C) Implement Serializable.
D) Implement Streamable.
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
40
What is returned by the read method when a FileInputStream has reached the end of the file?
A) -1
B) -2
C) '\n'
D) 0
A) -1
B) -2
C) '\n'
D) 0
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
41
Which of the following classes are used with data in binary form?
I FileInputStream
II FileReader
III RandomAccessFile
A) I
B) I and II
C) I and III
D) II and III
I FileInputStream
II FileReader
III RandomAccessFile
A) I
B) I and II
C) I and III
D) II and III
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
42
Which is not a method available in the RandomAccessFile class?
A) open
B) readInt
C) readDouble
D) close
A) open
B) readInt
C) readDouble
D) close
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
43
The ______ method returns an integer, either -1 (at the end of the file) or a byte between 0 and 255.
A) RandomAccessFile.seek
B) InputStream.read
C) Scanner.next
D) Reader.length
A) RandomAccessFile.seek
B) InputStream.read
C) Scanner.next
D) Reader.length
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
44
In Java, the byte type is a(n) ____ type.
A) positive
B) signed
C) negative
D) unsigned
A) positive
B) signed
C) negative
D) unsigned
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
45
Which method in the RandomAccessFile class provides for random access?
A) move
B) seek
C) goto
D) offset
A) move
B) seek
C) goto
D) offset
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
46
In Java, you use a(n) ____________ object to access a file and move its file pointer.
A) Stream
B) Serializable
C) SequentialAccessFile
D) RandomAccessFile
A) Stream
B) Serializable
C) SequentialAccessFile
D) RandomAccessFile
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
47
Given a RandomAccessFile that stores a set of records of class MyData, each needing MyData.RECORD_SIZE bytes for storage, which expression gets the offset to the beginning of the 25th record?
A) MyData.RECORD_SIZE * 25
B) MyData.RECORD_SIZE * 24
C) MyData.RECORD_SIZE++
D) MyData.RECORD_SIZE + 25
A) MyData.RECORD_SIZE * 25
B) MyData.RECORD_SIZE * 24
C) MyData.RECORD_SIZE++
D) MyData.RECORD_SIZE + 25
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
48
Assume we have a RandomAccessFile object, file, which stores a set of records of class MyData, each needing MyData.RECORD_SIZE bytes for storage. Which expression calculates the number of records in the file?
A) MyData.RECORD_SIZE * file.length()
B) MyData.RECORD_SIZE + file.getFilePointer()
C) file.seek(0L) / MyData.RECORD_SIZE
D) file.length() / MyData.RECORD_SIZE
A) MyData.RECORD_SIZE * file.length()
B) MyData.RECORD_SIZE + file.getFilePointer()
C) file.seek(0L) / MyData.RECORD_SIZE
D) file.length() / MyData.RECORD_SIZE
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
49
The values of the byte type range from ____ to ____.
A) 0, 255
B) 0, 256
C) -128, 128
D) -128, 127
A) 0, 255
B) 0, 256
C) -128, 128
D) -128, 127
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
50
Assume we have a RandomAccessFile object, file, which stores a set of records of class MyData, each needing MyData.RECORD_SIZE bytes for storage. If the file pointer is currently on the 24th record, which expression gets to the offset of the beginning of the 25th record?
A) MyData.RECORD_SIZE + 1
B) MyData.RECORD_SIZE + file.getFilePointer()
C) MyData.RECORD_SIZE * 2
D) file.getFilePointer()
A) MyData.RECORD_SIZE + 1
B) MyData.RECORD_SIZE + file.getFilePointer()
C) MyData.RECORD_SIZE * 2
D) file.getFilePointer()
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
51
Why does FileInputStream override the read method from its superclass InputStream?
A) In order to return a char.
B) In order to read binary data.
C) To read data from a file.
D) To check for end of file.
A) In order to return a char.
B) In order to read binary data.
C) To read data from a file.
D) To check for end of file.
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
52
Assume we have a RandomAccessFile object, file, that stores a set of records of class MyData. The size of each record is MyData.RECORD_SIZE. Assume MyData has read and write methods both of which take a RandomAccessFile as an argument. Method write writes the object at the current location. Method read reads the record from current location of the file into the object. If we are currently at the beginning of the 1st record, which code correctly modifies the 2nd record by changing its color to Color.red through the setColor method?
A) file.seek(MyData.RECORD_SIZE);
MyData.read(file);
MyData.setColor(Color.red);
File.seek(MyData.RECORD_SIZE);
MyData.write(file);
B) myData.read(file);
MyData.read(file);
MyData.setColor(Color.red);
MyData.write(file);
C) myData.read(file);
MyData.setColor(Color.red);
File.seek(file.getFilePointer() + MyData.RECORD_SIZE);
MyData.write(file);
D) long loc = file.getFilePointer();
MyData.read(file);
MyData.setColor(Color.red);
File.seek(loc);
MyData.write(file);
A) file.seek(MyData.RECORD_SIZE);
MyData.read(file);
MyData.setColor(Color.red);
File.seek(MyData.RECORD_SIZE);
MyData.write(file);
B) myData.read(file);
MyData.read(file);
MyData.setColor(Color.red);
MyData.write(file);
C) myData.read(file);
MyData.setColor(Color.red);
File.seek(file.getFilePointer() + MyData.RECORD_SIZE);
MyData.write(file);
D) long loc = file.getFilePointer();
MyData.read(file);
MyData.setColor(Color.red);
File.seek(loc);
MyData.write(file);
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
53
Which is not a method in the RandomAccessFile class?
A) getFilePointer
B) seek
C) scan
D) length
A) getFilePointer
B) seek
C) scan
D) length
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
54
In which of the following modes can a RandomAccessFiles be opened?
I "r"
II "rw"
III "w"
A) I
B) II
C) I and II
D) I and III
I "r"
II "rw"
III "w"
A) I
B) II
C) I and II
D) I and III
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
55
You would need a Caesar cipher with a shift of __________ to decrypt the following text, T U V W X Y Z A B C D E F G H I J K L M N O P Q R S, so that it reads A B C D E F G H I J K L M N O P Q R S T U V W X Y Z.
A) 7
B) 20
C) 19
D) -19
A) 7
B) 20
C) 19
D) -19
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
56
What do we call the measure in bytes of the file pointer from the beginning of a RandomAccessFile?
A) latency
B) offset
C) size
D) seek
A) latency
B) offset
C) size
D) seek
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
57
Assume we have a RandomAccessFile object, file, which stores a set of records of class MyData. The size of each record is MyData.RECORD_SIZE. Assume MyData has read and write methods, both of which take a RandomAccessFile as an argument. Method write writes the object at the current location. Method read reads the record from current location of the file into the object. If we are currently at the beginning of the 25th record, which code correctly modifies the 25th record by changing its color to Color.yellow through the setColor method?
A) myData.read(file);
MyData.setColor(Color.yellow);
MyData.write(file);
B) myData.read(file);
MyData.setColor(Color.yellow);
File.seek(file.getFilePointer());
MyData.write(file);
C) myData.read(file);
MyData.setColor(Color.yellow);
File.seek(file.getFilePointer() + MyData.RECORD_SIZE);
MyData.write(file);
D) long loc = file.getFilePointer();
MyData.read(file);
MyData.setColor(Color.yellow);
File.seek(loc);
MyData.write(file);
A) myData.read(file);
MyData.setColor(Color.yellow);
MyData.write(file);
B) myData.read(file);
MyData.setColor(Color.yellow);
File.seek(file.getFilePointer());
MyData.write(file);
C) myData.read(file);
MyData.setColor(Color.yellow);
File.seek(file.getFilePointer() + MyData.RECORD_SIZE);
MyData.write(file);
D) long loc = file.getFilePointer();
MyData.read(file);
MyData.setColor(Color.yellow);
File.seek(loc);
MyData.write(file);
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
58
Which code stores an array buttonArray of JButton objects in a file named buttonFile? We ignore exceptions in this problem.
A) ObjectStream os = new ObjectStream(new FileStream("buttonFile");
Os)writeObject(buttonArray);
B) ObjectOutputStream oos = new ObjectOutputStream(
New FileOutputStream("buttonFile");
Oos)writeObject(buttonArray);
C) ObjectOutputStream oos = new ObjectOutputStream(
New FileOutputStream("buttonFile");
Oos)writeObject(buttonArray[0]);
D) ObjectOutputStream oos = new ObjectOutputStream("buttonFile");
Oos)writeObject(buttonArray);
A) ObjectStream os = new ObjectStream(new FileStream("buttonFile");
Os)writeObject(buttonArray);
B) ObjectOutputStream oos = new ObjectOutputStream(
New FileOutputStream("buttonFile");
Oos)writeObject(buttonArray);
C) ObjectOutputStream oos = new ObjectOutputStream(
New FileOutputStream("buttonFile");
Oos)writeObject(buttonArray[0]);
D) ObjectOutputStream oos = new ObjectOutputStream("buttonFile");
Oos)writeObject(buttonArray);
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
59
In ____________ file access, the file is processed starting from the beginning.
A) random
B) serial
C) sequential
D) binary
A) random
B) serial
C) sequential
D) binary
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
60
__________ access allows file access at arbitrary locations, without first reading the bytes preceding the access location.
A) Random
B) Serial
C) Sequential
D) Binary
A) Random
B) Serial
C) Sequential
D) Binary
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
61
Objects saved to an object stream must belong to classes that:
A) implement the Serializable interface.
B) are RandomAccessFile objects.
C) are abstract.
D) implement the ObjectInputStream interface.
A) implement the Serializable interface.
B) are RandomAccessFile objects.
C) are abstract.
D) implement the ObjectInputStream interface.
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
62
Objects are saved in ___________ format in object streams.
A) binary
B) character
C) stream
D) integer
A) binary
B) character
C) stream
D) integer
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
63
Which methods are not in the Serializable interface?
I readObject
II writeObject
III serializeObject
A) I
B) I and II
C) II and III
D) I, II, and III
I readObject
II writeObject
III serializeObject
A) I
B) I and II
C) II and III
D) I, II, and III
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
64
When storing numbers in a file with fixed record sizes, it is easier to store them in __________ format.
A) character
B) text
C) binary
D) serializable
A) character
B) text
C) binary
D) serializable
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
65
Based on the code below, the statement that would move the file pointer to byte n counted from the beginning of the file is ___________________.
RandomAccessFile test = new RandomAccessFile("record.bat", "r");
A) test.getFilePointer(n);
B) test.getFilePointer();
C) test.seek(n);
D) test.length() - n;
RandomAccessFile test = new RandomAccessFile("record.bat", "r");
A) test.getFilePointer(n);
B) test.getFilePointer();
C) test.seek(n);
D) test.length() - n;
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
66
A file pointer is a position in a random access file. Because files can be very large,
The file pointer is of type _______.
A) double
B) byte
C) int
D) long
The file pointer is of type _______.
A) double
B) byte
C) int
D) long
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
67
Which interface allows classes to be written to an ObjectOutputStream?
A) Objective
B) Streaming
C) Serializable
D) Objectifiable
A) Objective
B) Streaming
C) Serializable
D) Objectifiable
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
68
How many methods are required to implement the Serializable interface?
A) 3
B) 2
C) 1
D) 0
A) 3
B) 2
C) 1
D) 0
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
69
The readDouble and writeDouble methods of the RandomAccessFile class, process double precision floating-point numbers as ____ quantities.
A) two-byte
B) four-byte
C) eight-byte
D) ten-byte
A) two-byte
B) four-byte
C) eight-byte
D) ten-byte
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
70
If serializing object obj requires 12 bytes, how many bytes are required to serialize obj 3 times?
A) 12 bytes plus 3 serial numbers of obj
B) 36 bytes
C) 12 bytes
D) 12 bytes plus 2 serial numbers of obj
A) 12 bytes plus 3 serial numbers of obj
B) 36 bytes
C) 12 bytes
D) 12 bytes plus 2 serial numbers of obj
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
71
Which method moves the file pointer in a RandomAccessFile?
A) seek
B) length
C) getFilePointer
D) close
A) seek
B) length
C) getFilePointer
D) close
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
72
Which code moves the file pointer to the middle of a RandomAccessFile object, file?
A) file.seek(file.length() / 2)
B) file.seek(file.length())
C) file.seek(0L)
D) file.seek(file.getFilePointer() / 2)
A) file.seek(file.length() / 2)
B) file.seek(file.length())
C) file.seek(0L)
D) file.seek(file.getFilePointer() / 2)
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
73
Which of the following cannot be serialized?
I ArrayList
II String
III Integer
A) I
B) II and III
C) III
D) All can be serialized
I ArrayList
II String
III Integer
A) I
B) II and III
C) III
D) All can be serialized
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
74
Which of these classes access sequences of characters?
I readers
II writers
III streams
A) I
B) II
C) I and II
D) II and III
I readers
II writers
III streams
A) I
B) II
C) I and II
D) II and III
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
75
Use a ____ object to access a file and move a file pointer.
A) Random
B) RandomAccess
C) RandomAccessFile
D) System.in
A) Random
B) RandomAccess
C) RandomAccessFile
D) System.in
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
76
The two IO classes used for serialization are _______ and ________.
A) Reader, Writer
B) ObjectInputStream, ObjectOutputStream
C) Scanner, PrintWriter
D) FileReader, FileWriter
A) Reader, Writer
B) ObjectInputStream, ObjectOutputStream
C) Scanner, PrintWriter
D) FileReader, FileWriter
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
77
Every object is assigned a serial number on the stream. What might be the result if the same object is saved twice?
A) The object will have two serial numbers.
B) Only the serial number is written out the second time.
C) A performance decrease.
D) Running out of serial numbers.
A) The object will have two serial numbers.
B) Only the serial number is written out the second time.
C) A performance decrease.
D) Running out of serial numbers.
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
78
The readInt and writeInt methods of the RandomAccessFile class read and write integers as ____ quantities.
A) two-byte
B) four-byte
C) six-byte
D) eight-byte
A) two-byte
B) four-byte
C) six-byte
D) eight-byte
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
79
Which of the following classes are related through inheritance?
I InputStream
II InputStreamReader
III ObjectInputStream
A) I and II
B) I and III
C) II and III
D) I, II and III
I InputStream
II InputStreamReader
III ObjectInputStream
A) I and II
B) I and III
C) II and III
D) I, II and III
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck
80
In which package are most classes for file processing found?
A) java.file
B) java.inputoutput
C) java.io
D) java.stream
A) java.file
B) java.inputoutput
C) java.io
D) java.stream
Unlock Deck
Unlock for access to all 82 flashcards in this deck.
Unlock Deck
k this deck