chap 11 Flashcards
What is a call stack?
an internal list of all the methods that are currently executing.
What is a stack trace?
a list of all the methods in the call stack.
What is a random access file?
a file that allows a program to read data from any location within the file, or write data to any location within the file.
What is object serialization?
the process of converting an object to a series of bytes and saving them to a file.
What is Deserialization
the process of reconstructing a serialized object.
When an exception is thrown ____
a) it may be ignored
b) it must always be handled by the method that throws it
c) the program terminates even if the exception is handled
d) it must be handled by the program of by the default exception handler
d) it must be handled by the program of by the default exception handler
When writing a string to a binary file or reading a string from a binary file, it is recommended that you use ____
a) the FileReader and Writer class methods
b) the Scanner class methods
c) the System.In and System.out methods
d) methods that use UTF-8 encoding
d) methods that use UTF-8 encoding
When writing or reading strings to/from a binary file, it’s recommended to use methods that handle character encoding properly, such as those that use UTF-8 encoding. This ensures that the characters are properly encoded and decoded without losing information or encountering unexpected behavior.
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 ___
a) each catch clause that can handle the exception
b) the statement that appears immediately after the catch block
c) the first catch clause that can handle the exception
d) the last catch clause that can handle the exception
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:
c) the first catch clause that can handle the exception
to read data from a binary file, you create objects from which of the following classes
a) File and PrintWriter
b) FileInputStream and DataInputStream
c) BinaryFileReader and BinaryDataReader
d) File and Scanner
b) FileInputStream and DataInputStream
Beginning with Java7, to catch multiple exceptions with a single catch, you can use ___
a) catch templates
b) multi-catch
c) catchAll
d) multi-try
b) multi-catch
Beginning with Java 7, you can catch multiple exceptions with a single catch block using the multi-catch feature. This allows you to write cleaner and more concise exception handling code.
to serialize an object and write it to the file, use the ____ method of the ObjectOutputStream class
a) Serialize
b) SerializeObject
c) SerializeAndWrite
d) WriteObject
d) WriteObject
When you want to serialize an object and write it to a file in Java, you use the WriteObject method of the ObjectOutputStream class. This method is specifically designed to write the state of an object to the underlying stream, allowing you to persist the object’s data to a file for later retrieval or transmission. It’s a standard practice for object serialization in Java.
what happens if a program does not handle an unchecked exception?
a) The program is halted and the default exception handler handles the exception
b) A compiler error will occur
c) This isn’t possible; the program will handle the exception
d) The exception is ignored
If a program does not handle an unchecked exception, the following occurs:
a) The program is halted and the default exception handler handles the exception
What is the main difference between checked and unchecked exceptions?
The main difference between checked and unchecked exceptions in Java is that checked exceptions are checked at compile time, while unchecked exceptions are not checked at compile time.
Checked exceptions are subclasses of Exception class, excluding RuntimeException and its subclasses.
Unchecked exceptions are subclasses of RuntimeException and Error.
What is the file pointer?
The file pointer holds the byte number of a location in the file. When a file is first opened, the file pointer is set to 0. This causes it to “point” to the first byte in the file. When an item is read from the file, it is read from the byte that the file pointer points to.