CSCI-C201 FINAL EXAM QUESTIONS & ANSWERS
What is the purpose of Serializable interface? How one could use it? - Answers -The
purpose of the serializable interface is to allow for objects to be saved easier. When an
object is serialized, it is converted into a series of bytes that contain the object's data.
The resulting set of bytes can be saved to a file for later retrieval. You can use the
serializable interface by implementing it into your Java class.
When an exception is thrown by code in its try block, the JVM begins searching the try
statement for a catch clause that can handle it and passes control of the program to
_____________. - Answers -The first catch clause that is able to handle the exception
In the following code, assume that inputFile references a Scanner object that has been
successfully used to open a file:
double totalIncome = 0.0;while (inputFile.hasNext()){ try{ totalIncome +=
inputFile.nextDouble(); }catch(InputMismatchException e){ System.out.println("Non-
numeric data encountered " + "in the file."); inputFile.nextLine(); }finally{ totalIncome =
35.5; }}
What will be the value of totalIncome after the following values are read from the file?
2.58.53.05.5abc1.0
35.5 - Answers -35.5
What is Random Access File? Explain the I/O operations of Random Access Files. -
Answers -Random Access File is a file that allows a program to jump to any location in
the file. Items in a Random Access File are accessed in any order. The Random Access
File class treats a file as a stream of bytes. Bytes are numbered, starting at 0, similar to
an array. Java accesses the file through a file pointer. When the file is first opened, the
file pointer is set to 0. When an item is read it reads from that byte. This allows data to
be read and written at any byte location in the file.
If an exception is thrown and the program does not handle it, what happens? - Answers
-If an exception is thrown and the program does not handle it, it is thrown up to calling
method. It is handled by the default exception handler which will print an error message
and crash the program.
What will be the result of the following statements?
FileInputStream fstream = new FileInputStream("Input.dat");
DataInputStream inFile = new DataInputStream(fstream); - Answers -The
DataInputStream object is stored in the variable called inFile. The inFile variable will
reference an object that is able to read binary data from the file.
Assume that the classes BlankISBN, NegativePrice, and NegativeNumberOrdered are
exception classes that inherit from Exception. The following code is a constructor for the
Book class. What must be true about any method that instantiates the Book class with
What is the purpose of Serializable interface? How one could use it? - Answers -The
purpose of the serializable interface is to allow for objects to be saved easier. When an
object is serialized, it is converted into a series of bytes that contain the object's data.
The resulting set of bytes can be saved to a file for later retrieval. You can use the
serializable interface by implementing it into your Java class.
When an exception is thrown by code in its try block, the JVM begins searching the try
statement for a catch clause that can handle it and passes control of the program to
_____________. - Answers -The first catch clause that is able to handle the exception
In the following code, assume that inputFile references a Scanner object that has been
successfully used to open a file:
double totalIncome = 0.0;while (inputFile.hasNext()){ try{ totalIncome +=
inputFile.nextDouble(); }catch(InputMismatchException e){ System.out.println("Non-
numeric data encountered " + "in the file."); inputFile.nextLine(); }finally{ totalIncome =
35.5; }}
What will be the value of totalIncome after the following values are read from the file?
2.58.53.05.5abc1.0
35.5 - Answers -35.5
What is Random Access File? Explain the I/O operations of Random Access Files. -
Answers -Random Access File is a file that allows a program to jump to any location in
the file. Items in a Random Access File are accessed in any order. The Random Access
File class treats a file as a stream of bytes. Bytes are numbered, starting at 0, similar to
an array. Java accesses the file through a file pointer. When the file is first opened, the
file pointer is set to 0. When an item is read it reads from that byte. This allows data to
be read and written at any byte location in the file.
If an exception is thrown and the program does not handle it, what happens? - Answers
-If an exception is thrown and the program does not handle it, it is thrown up to calling
method. It is handled by the default exception handler which will print an error message
and crash the program.
What will be the result of the following statements?
FileInputStream fstream = new FileInputStream("Input.dat");
DataInputStream inFile = new DataInputStream(fstream); - Answers -The
DataInputStream object is stored in the variable called inFile. The inFile variable will
reference an object that is able to read binary data from the file.
Assume that the classes BlankISBN, NegativePrice, and NegativeNumberOrdered are
exception classes that inherit from Exception. The following code is a constructor for the
Book class. What must be true about any method that instantiates the Book class with