Exception Handling Java Interview Questions – Set 07

Explain how you would get thread-safety issues due to non-atomic operations with a code example The code snippets below demonstrates non-atomic operations producing incorrect results with code. The program below uses a shared Counter object, that is shared between three concurrent users (i.e. three threads). The Counter object is responsible for incrementing the counter. Firstly, the Counter class. … Read more

Exception Handling Java Interview Questions – Set 06

When do we say an exception is not handled There is no catch block that names either the class of exception that has been thrown or a class of exception that is a parent class of the one that has been thrown, then the exception is considered to be unhandled, in such condition the execution … Read more

Exception Handling Java Interview Questions – Set 05

How do you intercept and thereby control exceptions We can do this by using try/catch/finally blocks You place the normal processing code in try block You put the code to deal with exceptions that might arise in try block in catch block Code that must be executed no matter what happens must be place in … Read more

Exception Handling Java Interview Questions – Set 04

 What can prevent the execution of the code in finally block ? and what are the rules for catching multiple exceptions? The death of thread – Use of system.exit() – Turning off the power to CPU – An exception arising in the finally block itself Rules for catching multiple exceptions – A more specific catch … Read more

Exception Handling Java Interview Questions – Set 03

What happens if an exception is not caught An uncaught exception results in the uncaughtException() method of the thread’s ThreadGroup being invoked, which eventually results in the termination of the program in which it is thrown. What happens if a try-catch-finally statement does not have a catch clause to handle an exception that is thrown within the body of … Read more