Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java Questions Question 1: File = InputStream = OutputStream = FileWrite = FileC

ID: 3842366 • Letter: J

Question

Java Questions

Question 1:

File =
InputStream =
OutputStream =
FileWrite =
FileClass =
ObjectInputStream =
Serializable =
ObjectOutputStream =

A. An abstract class that defines methods for performing input.

B. An abstract class that defines methods for performing output.

C. A tagging interface that allows objects of a class to be used with object streams.

D. Used to read objects from a stream

E. Used by programs to obtain information about a file or directory

F. Group of related records

G. Objects of this class write characters to a file

H. Used to write objects to a stream

Question 2:
A good programming practice for I/O in Java is
      
a. have objects do their own I/O
b. design a single class to do all I/O for the program
c. avoid file I/O since it is inefficient
d. never append to a file

Question 3:
Every program that does file I/O
  
a. must include the line "include io.java" somewhere in the program
b. can do input from a file or output to a file but not both
c. must be designed specifically for the operating system in which it will run
d. must include the line "import java.io.*" near the beginning

Question 4:
If a new output text file cannot be created

a. a FileNotCreatedException will be thrown
b. a FileNotFoundException will be thrown
c. The program will stop executing with an error message
d. the program will continue executing and might produce incorrect results

Qustion 5:
If an open file is not closed when the program finishes executing

a. a FileNotClosed exception will be thrown
b. the contents of the file will be lost
c. Java will close the file but it is better to explicitly close the file
d. no other program will be able to open the file

Question 6:
If data in a stream flows out of a file then the stream is an output stream.

a. True
b. False

Question 7:
The preferred way to open a text file is to pass the file name to the constructor for BufferedReader.

a. True
c. False

Question 8:
When a program tries to read beyond the end of a file, the read method returns the value -1

a. True
b. False

Question 9:
Opening a text file for writing

a. requires use of the PrintWriter constructor
b. requires use of the FileOutputStream constructor
c. requires the use of the PrintWriter constructor and the FileOutputStream constructor
d. the program will continue executing and might produce incorrect results

Question 10:
The classes used to open a binary file for writing are

a. PrintWriter and FileOutputStream
b. ObjectOutputStream and FIleOutputStream
c. PrintWriter and ObjectOutputStream
d. Buffered Writer and ObjectOutputStream

Question 11:
Write a sequence of statements that create a file named "fileio.txt" and write a single line consisting "Hello, World!" to that file, then close the file.

Explanation / Answer

Question 1:
File = E. Used by programs to obtain information about a file or directory
InputStream = A. An abstract class that defines methods for performing input.
OutputStream = B. An abstract class that defines methods for performing output.
FileWrite = G. Objects of this class write characters to a file
FileClass = F. Group of related records
ObjectInputStream = D. Used to read objects from a stream
Serializable = C. A tagging interface that allows objects of a class to be used with object streams.
ObjectOutputStream = H. Used to write objects to a stream


Question 2:

a. have objects do their own I/O


Question 3:

d. must include the line "import java.io.*" near the beginning


Question 4:

b. a FileNotFoundException will be thrown

Explanation:- If the directory does not exists where the file should be created it wiil throw FileNotFoundException

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote