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

Exception Handling Java Interview Questions – Set 02

What is immutable object in Java? Can you change values of a immutable object? A Java object is considered immutable when its state cannot change after it is created. Use of immutable objects is widely accepted as a sound strategy for creating simple, reliable code. Immutable objects are particularly useful in concurrent applications. Since they … Read more

Exception Handling Java Interview Questions – Set 01

What is the difference between checked and unchecked exceptions? In general, unchecked exceptions represent defects in the program (bugs), which are normally Runtime exceptions. Furthermore, checked exceptions represent invalid conditions in areas outside the immediate control of the program. Explain Checked Exceptions and Unchecked Exceptions with examples Unchecked exceptions : represent defects in the program … Read more

Exception Handling Java Interview Questions

Exception Handling Java Interview Questions – Set 07 Exception Handling Java Interview Questions – Set 06 Exception Handling Java Interview Questions – Set 05 Exception Handling Java Interview Questions – Set 04 Exception Handling Java Interview Questions – Set 03 Exception Handling Java Interview Questions – Set 02 Exception Handling Java Interview Questions – Set … Read more