Advanced File I/O Questions and
Answers Already Passed
What is an exception in Java?
✔✔ An exception is an event that disrupts the normal flow of a program during execution.
How do you handle exceptions in Java?
✔✔ Exceptions in Java are handled using try-catch blocks.
What keyword is used to manually throw an exception in Java?
✔✔ The `throw` keyword is used to manually throw an exception.
What is the difference between checked and unchecked exceptions?
✔✔ Checked exceptions must be handled using a try-catch block or declared using `throws`,
while unchecked exceptions do not require explicit handling.
What is the purpose of the `finally` block in exception handling?
✔✔ The `finally` block is used to execute code regardless of whether an exception occurs or not.
1
, What happens if an exception is not caught in Java?
✔✔ If an exception is not caught, the program terminates and an error message is displayed.
What is the superclass of all exception classes in Java?
✔✔ The `Throwable` class is the superclass of all exception classes.
How do you declare that a method may throw an exception?
✔✔ A method declares exceptions using the `throws` keyword in its signature.
What is a `try-with-resources` statement?
✔✔ It is a special try block that automatically closes resources like files or streams when
execution exits the block.
What kind of exceptions does a `try-with-resources` statement handle?
✔✔ It is primarily used for handling checked exceptions related to file and resource
management.
2