Deck 10: Exceptions and Advanced File I/O

ملء الشاشة (f)
exit full mode
سؤال
To serialize an object and write it to the file, use this method of the ObjectOutputStream class.

A) WriteObject
B) SerializeObject
C) Serialize
D) SerializeAndWrite
استخدم زر المسافة أو
up arrow
down arrow
لقلب البطاقة.
سؤال
All of the exceptions that you will handle are instances of classes that extend this class.

A) IOException
B) Exception
C) Error
D) RunTimeException
سؤال
To write data to a binary file, you create objects from the following classes:

A) File and Scanner.
B) BinaryFileWriter and BinaryDataWriter.
C) FileOutputStream and DataOutputStream.
D) File and PrintWriter.
سؤال
When writing a string to a binary file or reading a string from a binary file, it is recommended that you use

A) methods that use UTF-8 encoding.
B) the FileReader and Writer class methods.
C) the Scanner class methods.
D) the System.In and System.Out methods.
سؤال
The following catch clause
Catch (Exception e)

A) can handle all throwable objects by using a polymorphic reference for the parameter.
B) can handle all exceptions that are instances of the Exception class or one of its subclasses.
C) can handle all exceptions that are instances of the Exception class, but not its subclasses.
D) causes a compiler error.
سؤال
In order for an object to be serialized, the class must implement this interface.

A) Serial
B) Serializable
C) ObjectOutputStream
D) Writable
سؤال
Classes that inherit from the Error class are

A) for exceptions that are thrown when an IOException occurs, and the application program should not try to handle them.
B) for exceptions that are thrown when a critical error occurs, and the application program should not try to handle them.
C) for exceptions that are thrown when an IOException error occurs, and the application program should try to handle them.
D) for exceptions that are thrown when a critical error occurs, and the application program should try to handle them.
سؤال
What will be the result of the following statements?
FileInputStream fstream = new FileInputStream("Input.dat"); DataInputStream inFile = new DataInputStream(fstream);

A) The inFile variable will reference an object that is able to read random access data from the Input.dat file.
B) The inFile variable will reference an object that is able to read text data from the Input.dat file.
C) The inFile variable will reference an object that is able to read binary data from the Input.dat file.
D) The inFile variable will reference an object that is able to write binary data to the Input.dat file.
سؤال
To read data from a binary file, you create objects from the following classes:

A) File and Scanner.
B) File and PrintWriter.
C) BinaryFileReader and BinaryDataReader.
D) FileInputStream and DataInputStream .
سؤال
An exception object's default error message can be retrieved using this method.

A) getMessage
B) getDefaultMessage
C) getDefaultErrorMessage
D) getErrorMessage
سؤال
In a catch statement, what does the following code do?
System.out.println(e.getMessage());

A) It prints the code that caused the exception.
B) It prints the stack trace.
C) It prints the error message for an exception.
D) It overrides the toString method.
سؤال
The catch clause

A) starts with the word catch followed by a parameter list in parentheses containing an ExceptionType parameter variable.
B) follows the try clause.
C) contains code to gracefully handle the exception type listed in the parameter list.
D) All of the above
سؤال
When you write a method that throws a checked exception, you must

A) override the default error method.
B) ensure that the error will occur at least once each time the program is executed.
C) have a throws clause in the method header.
D) use each class only once in a method.
سؤال
What will the following code display?
String input = "99#7";
Int number;
Try
{
Number = Integer.parseInt(input);
}
Catch(NumberFormatException ex)
{
Number = 0;
}
Catch(RuntimeException ex)
{
Number = 1;
}
Catch(Exception ex)
{
Number = -1;
}
System.out.println(number);

A) -1
B) 0
C) 1
D) 99
سؤال
If a program does not handle an unchecked exception, what is the result?

A) The program must handle the exception.
B) The program is halted and the default exception handler handles the exception.
C) The exception is ignored.
D) A compiler error will occur.
سؤال
A(n) ________ is an object that is generated in memory as the result of an error or an unexpected event.

A) exception
B) exception handler
C) default exception handler
D) error message
سؤال
When an exception is thrown,

A) it must always be handled by the method that throws it.
B) it must be handled by the program or by the default exception handler.
C) it may be ignored.
D) the program terminates even if the exception is handled.
سؤال
Look at the following code:
FileInputStream fstream = new FileInputStream("info.dat"); DataInputStream inputFile = new DataInputStream(fstream);
This code could also be written as

A) DataInputStream inputFile = new DataInputStream(new FileInputStream("info.dat"));
B) DataInputStream inputFile = new DataInputStream("info.txt");
C) FileInputStream inputFile = new FileInputStream(new DataInputStream("info.dat"));
D) FileInputStream fstream = new DataInputStream("info.txt");
سؤال
A(n) ________ is one or more statements that are executed and can potentially throw an exception.

A) exception block
B) catch block
C) try block
D) error block
سؤال
Beginning in Java 7, you can use ________ to reduce a lot of duplicated code in a try statement that needs to catch multiple exceptions, but perform the same operation for each one.

A) multi-catch
B) catch templates
C) multi-try
D) catchAll
سؤال
When an object is serialized, it is converted into a series of bytes that contain the object's data.
سؤال
When catching multiple exceptions that are related to one another through inheritance, you should handle the more specialized exception classes before the more general exception classes.
سؤال
A file that contains raw binary data is known as a(n)

A) binary file.
B) machine file.
C) serial file.
D) raw data file.
سؤال
The call stack is an internal list of all the methods that are currently executing.
سؤال
The RandomAccessFile class treats a file as a stream of

A) bytes.
B) characters.
C) integers.
D) data.
سؤال
If a method does not handle a possible checked exception, what must the method have?

A) a try clause in its header
B) a catch clause in its header
C) a finally clause in its header
D) a throws clause in its header
سؤال
If a random access file contains a stream of characters, which of the following statements would move the file pointer to the starting byte of the fifth character in the file?

A) file.seek(4);
B) file.seek(8);
C) file.seek(10);
D) file.seek(5);
سؤال
This is a section of code that gracefully responds to exceptions when they are thrown.

A) exception
B) default exception handler
C) exception handler
D) thrown class
سؤال
Unchecked exceptions are those that inherit from the

A) Error class or the RuntimeException class.
B) Error class or the Exception class.
C) Error class.
D) Exception Class or the RuntimeException class.
سؤال
The throw statement informs the compiler that a method throws one or more exception.
سؤال
The throws clause causes an exception to be thrown.
سؤال
When you deserialize an object using the readObject method, you must cast the return value to the desired class type.
سؤال
In Java, there are two categories of exceptions:

A) unchecked and checked.
B) runtime and compile-time.
C) critical and nominal.
D) static and dynamic.
سؤال
When using the throw statement, if you do not pass a message to the exception object's constructor,

A) the exception will have a null message.
B) the exception will have a message containing the address of the exception.
C) the exception will a default message describing the exception.
D) a compiler error will occur.
سؤال
The ability to catch multiple types of exceptions with a single catch clause is known as multi-catch, and was introduced in Java 7.
سؤال
When an exception is thrown by code in the 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) the last catch clause that can handle the exception.
B) each catch clause that can handle the exception.
C) the first catch clause that can handle the exception.
D) the statement that appears immediately after the catch block.
سؤال
A class must implement the Serializable interface in order for objects of the class to be serialized.
سؤال
If a class has fields that are objects of other classes, those classes must implement the Serializable interface in order to be serialized.
سؤال
If the data.dat file does not exist, what will happen when the following statement is executed?
RandomAccessFile randomFile = new RandomAccessFile("data.dat", "rw");

A) An IOExcepton will be thrown.
B) The file data.dat will be created.
C) A FileNotFoundException will be thrown.
D) A compiler error will occur.
سؤال
In a try statement, the try clause must appear first, followed by all of the catch clauses, followed by the optional finally clause.
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/40
auto play flashcards
العب
simple tutorial
ملء الشاشة (f)
exit full mode
Deck 10: Exceptions and Advanced File I/O
1
To serialize an object and write it to the file, use this method of the ObjectOutputStream class.

A) WriteObject
B) SerializeObject
C) Serialize
D) SerializeAndWrite
A
2
All of the exceptions that you will handle are instances of classes that extend this class.

A) IOException
B) Exception
C) Error
D) RunTimeException
B
3
To write data to a binary file, you create objects from the following classes:

A) File and Scanner.
B) BinaryFileWriter and BinaryDataWriter.
C) FileOutputStream and DataOutputStream.
D) File and PrintWriter.
C
4
When writing a string to a binary file or reading a string from a binary file, it is recommended that you use

A) methods that use UTF-8 encoding.
B) the FileReader and Writer class methods.
C) the Scanner class methods.
D) the System.In and System.Out methods.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
5
The following catch clause
Catch (Exception e)

A) can handle all throwable objects by using a polymorphic reference for the parameter.
B) can handle all exceptions that are instances of the Exception class or one of its subclasses.
C) can handle all exceptions that are instances of the Exception class, but not its subclasses.
D) causes a compiler error.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
6
In order for an object to be serialized, the class must implement this interface.

A) Serial
B) Serializable
C) ObjectOutputStream
D) Writable
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
7
Classes that inherit from the Error class are

A) for exceptions that are thrown when an IOException occurs, and the application program should not try to handle them.
B) for exceptions that are thrown when a critical error occurs, and the application program should not try to handle them.
C) for exceptions that are thrown when an IOException error occurs, and the application program should try to handle them.
D) for exceptions that are thrown when a critical error occurs, and the application program should try to handle them.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
8
What will be the result of the following statements?
FileInputStream fstream = new FileInputStream("Input.dat"); DataInputStream inFile = new DataInputStream(fstream);

A) The inFile variable will reference an object that is able to read random access data from the Input.dat file.
B) The inFile variable will reference an object that is able to read text data from the Input.dat file.
C) The inFile variable will reference an object that is able to read binary data from the Input.dat file.
D) The inFile variable will reference an object that is able to write binary data to the Input.dat file.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
9
To read data from a binary file, you create objects from the following classes:

A) File and Scanner.
B) File and PrintWriter.
C) BinaryFileReader and BinaryDataReader.
D) FileInputStream and DataInputStream .
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
10
An exception object's default error message can be retrieved using this method.

A) getMessage
B) getDefaultMessage
C) getDefaultErrorMessage
D) getErrorMessage
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
11
In a catch statement, what does the following code do?
System.out.println(e.getMessage());

A) It prints the code that caused the exception.
B) It prints the stack trace.
C) It prints the error message for an exception.
D) It overrides the toString method.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
12
The catch clause

A) starts with the word catch followed by a parameter list in parentheses containing an ExceptionType parameter variable.
B) follows the try clause.
C) contains code to gracefully handle the exception type listed in the parameter list.
D) All of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
13
When you write a method that throws a checked exception, you must

A) override the default error method.
B) ensure that the error will occur at least once each time the program is executed.
C) have a throws clause in the method header.
D) use each class only once in a method.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
14
What will the following code display?
String input = "99#7";
Int number;
Try
{
Number = Integer.parseInt(input);
}
Catch(NumberFormatException ex)
{
Number = 0;
}
Catch(RuntimeException ex)
{
Number = 1;
}
Catch(Exception ex)
{
Number = -1;
}
System.out.println(number);

A) -1
B) 0
C) 1
D) 99
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
15
If a program does not handle an unchecked exception, what is the result?

A) The program must handle the exception.
B) The program is halted and the default exception handler handles the exception.
C) The exception is ignored.
D) A compiler error will occur.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
16
A(n) ________ is an object that is generated in memory as the result of an error or an unexpected event.

A) exception
B) exception handler
C) default exception handler
D) error message
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
17
When an exception is thrown,

A) it must always be handled by the method that throws it.
B) it must be handled by the program or by the default exception handler.
C) it may be ignored.
D) the program terminates even if the exception is handled.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
18
Look at the following code:
FileInputStream fstream = new FileInputStream("info.dat"); DataInputStream inputFile = new DataInputStream(fstream);
This code could also be written as

A) DataInputStream inputFile = new DataInputStream(new FileInputStream("info.dat"));
B) DataInputStream inputFile = new DataInputStream("info.txt");
C) FileInputStream inputFile = new FileInputStream(new DataInputStream("info.dat"));
D) FileInputStream fstream = new DataInputStream("info.txt");
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
19
A(n) ________ is one or more statements that are executed and can potentially throw an exception.

A) exception block
B) catch block
C) try block
D) error block
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
20
Beginning in Java 7, you can use ________ to reduce a lot of duplicated code in a try statement that needs to catch multiple exceptions, but perform the same operation for each one.

A) multi-catch
B) catch templates
C) multi-try
D) catchAll
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
21
When an object is serialized, it is converted into a series of bytes that contain the object's data.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
22
When catching multiple exceptions that are related to one another through inheritance, you should handle the more specialized exception classes before the more general exception classes.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
23
A file that contains raw binary data is known as a(n)

A) binary file.
B) machine file.
C) serial file.
D) raw data file.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
24
The call stack is an internal list of all the methods that are currently executing.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
25
The RandomAccessFile class treats a file as a stream of

A) bytes.
B) characters.
C) integers.
D) data.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
26
If a method does not handle a possible checked exception, what must the method have?

A) a try clause in its header
B) a catch clause in its header
C) a finally clause in its header
D) a throws clause in its header
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
27
If a random access file contains a stream of characters, which of the following statements would move the file pointer to the starting byte of the fifth character in the file?

A) file.seek(4);
B) file.seek(8);
C) file.seek(10);
D) file.seek(5);
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
28
This is a section of code that gracefully responds to exceptions when they are thrown.

A) exception
B) default exception handler
C) exception handler
D) thrown class
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
29
Unchecked exceptions are those that inherit from the

A) Error class or the RuntimeException class.
B) Error class or the Exception class.
C) Error class.
D) Exception Class or the RuntimeException class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
30
The throw statement informs the compiler that a method throws one or more exception.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
31
The throws clause causes an exception to be thrown.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
32
When you deserialize an object using the readObject method, you must cast the return value to the desired class type.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
33
In Java, there are two categories of exceptions:

A) unchecked and checked.
B) runtime and compile-time.
C) critical and nominal.
D) static and dynamic.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
34
When using the throw statement, if you do not pass a message to the exception object's constructor,

A) the exception will have a null message.
B) the exception will have a message containing the address of the exception.
C) the exception will a default message describing the exception.
D) a compiler error will occur.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
35
The ability to catch multiple types of exceptions with a single catch clause is known as multi-catch, and was introduced in Java 7.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
36
When an exception is thrown by code in the 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) the last catch clause that can handle the exception.
B) each catch clause that can handle the exception.
C) the first catch clause that can handle the exception.
D) the statement that appears immediately after the catch block.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
37
A class must implement the Serializable interface in order for objects of the class to be serialized.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
38
If a class has fields that are objects of other classes, those classes must implement the Serializable interface in order to be serialized.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
39
If the data.dat file does not exist, what will happen when the following statement is executed?
RandomAccessFile randomFile = new RandomAccessFile("data.dat", "rw");

A) An IOExcepton will be thrown.
B) The file data.dat will be created.
C) A FileNotFoundException will be thrown.
D) A compiler error will occur.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
40
In a try statement, the try clause must appear first, followed by all of the catch clauses, followed by the optional finally clause.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
locked card icon
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.