DEV Community

Pramod Bablad
Pramod Bablad

Posted on

Most Likely Java Exception Handling Interview Questions

1) What is an exception?
2) How the exceptions are handled in Java?
3) What is the difference between error and exception in Java?
4) Can we keep other statements in between try, catch and finally blocks?
5) Can we write only try block without catch and finally blocks?
6) There are three statements in a try block – statement1, statement2 and statement3. After that there is a catch block to catch the exceptions occurred in the try block. Assume that exception has occurred in statement2. Does statement3 get executed or not?
7) What is unreachable catch block error?
8) Explain the hierarchy of exceptions in Java?
9) What are run time exceptions in Java. Give example?
10) What is OutOfMemoryError in Java?
11) what are checked and unchecked exceptions in Java?
12) What is the difference between ClassNotFoundException and NoClassDefFoundError in Java?
13) Can we keep the statements after finally block If the finally block is returning the control?
14) Does finally block get executed If either try or catch blocks are returning the control?
15) Can we throw an exception manually? If yes, how?
16) What is Re-throwing an exception in Java?
17) What is the use of throws keyword in Java?
18) Why it is always recommended that clean up operations like closing the DB resources to keep inside a finally block?
19) What is the difference between final, finally and finalize in Java?
20) How do you create customized exceptions in Java?
21) What is ClassCastException in Java?
22) What is the difference between throw, throws and throwable in Java?
23) What is StackOverflowError in Java?
24) Can we override a super class method which is throwing an unchecked exception with checked exception in the sub class?
25) What are chained exceptions in Java?
26) Which class is the super class for all types of errors and exceptions in Java?
27) What are the legal combinations of try, catch and finally blocks?
28) What is the use of printStackTrace() method?
29) Give some examples to checked exceptions?
30) Give some examples to unchecked exceptions?
31) Do you know try-with-resources blocks? Why do we use them? When they are introduced?
32) What are the benefits of try-with-resources?
33) What are the changes made to exception handling from Java 7?
34) What are the improvements made to try-with-resources in Java 9?
35) What are the differences between StackOverflowError and OutOfMemoryError In Java?

See the answers at https://javaconceptoftheday.com/java-exception-handling-interview-questions-and-answers/

Top comments (0)