Java Exception Handling Interview Questions and Answers
Here you can find Java Exception Handling Interview Questions and Answers.
Why Java Exception Handling Interview Questions and Answers Required?
In this Java Exception Handling Interview Questions and Answers section you can learn and practice Java Exception Handling Interview Questions and Answers to improve
your skills in order to face technical inerview by IT companies. By Practicing these interview questions, you can easily crack any Java Exception Handling interview.
Where can I get Java Exception Handling Interview Questions and Answers?
AllIndiaExams provides you lots Java Exception Handling Interview Questions and Answers with proper explanation. Fully solved examples with detailed answer description.
All students, freshers can download Java Exception Handling Interview Questions and Answers as PDF files and eBooks.
How to solve these Java Exception Handling Interview Questions and Answers?
You no need to worry, we have given lots of Java Exception Handling Interview Questions and Answers and also we have provided lots of FAQ's to quickly answer the
questions in the Java Exception Handling technical interview.
Java Exception Handling Interview Questions and Answers
What is an Exception?
An unwanted, unexpected event that disturbs normal flow of the program is called Exception
Example: FileNotFondException.
Java Exception Handling Interview Questions and Answers
What is the purpose of Exception Handling?
The main purpose of Exception Handling is for graceful termination of the program.
Java Exception Handling Interview Questions and Answers
What is the meaning of Exception Handling?
Exception Handling doesn’t mean repairing an Exception, we have to define alternative way to continue rest of the code normally.
Example: If our programming requirement is to read the data from the file locating at London but at Runtime if London file is not available then we have to use local file
alternatively to continue rest of program normally. This is nothing but Exception Handling.
Java Exception Handling Interview Questions and Answers
Explain Default Exception Handling Mechanism in Java?
If an exception raised, the method in which it’s raised is responsible for the creation of Exceptions object by including the following information:
=> Name of the Exception
=> Description of the Exception
=> Stack Trace
=> After creating Exception object the method handover it to the JVM.
=> JVM checks for Exception Handling code in that method.
=> If the method doesn’t contain any Exception handling code then JVM terminates the method abnormally and removes the corresponding entry from the stack.
=> JVM identify the caller method and checks for Exception Handling code in that method. If the caller doesn’t contain any exception handling code then JVM terminates that
method abnormally and removes the corresponding entry from the stack.
=> This process will be continue until main() method.
=> If the main() method also doesn’t contain exception handling code the JVM terminates that main() method and removes the corresponding entry from the stack.
Just before terminating the program abnormally JVM handovers the responsibility of exception handling to the Default Exception Handler which is the component of
JVM.
Default Exception Handler just print exception information to the consol in the following format
Name of Exception: Description
Stack Trace (Location of the Exception)
Java Exception Handling Interview Questions and Answers
What is the purpose of try?
We should maintain all risky code inside the try block.
Java Exception Handling Interview Questions and Answers
What is the purpose of catch block?
We have to maintain all Exception Handling code inside the catch block.
Java Exception Handling Interview Questions and Answers
Is try with multiple catch block is possible?
The way of handling an exception is varied from exception to exception compulsory we have to write a separate catch block for every exception. Hence try will multiple catch
block is possible and it is recommended to use.
Example:
try{
//Risky code
}
catch(IOException e)
{
//Hndling code for IOException
}
catch(ArithmeticException e)
{
//handling code for AE
}
catch(NullPointerExcetpion e)
{
// handling code for NPE
}
catch(Exception e)
{
//default exception handling code
}
Java Exception Handling Interview Questions and Answers
If try with multiple catch block present is order of catch blocks important in which order we have to take?
If try with multiple catch block present then the order of catch block is very important it should be from child to parent but not from parent to child.
Java Exception Handling Interview Questions and Answers
What are various methods to print Exception information? and differentiate them?
Throwable class defines the following method to print exception or error information .
1. printStackTrace() :- This method print exception information in the following format.
Name of the Exception: Description
StackTrace
2.toString():- This method print exception information in the following format.
Name of the Exception: Description
3.getMessage():- This method prints only description of the exception.
Java Exception Handling Interview Questions and Answers
If an exception rised inside catch block then what will happen?
If an exception raised inside catch block and it is not part of any try block then it is always abnormal termination.