Top 1000+ Advanced Java Interview Questions 2020-2021 - 1
Question: 1
What are the exception handling keyword in java?
There are four keywords used in java exception handling.
throw
throws
try-catch
finally
throw:
Sometimes we explicitly want to create exception object and then throw it to halt the normal processing of the program.
throw keyword is used to throw exception to the run time to handle it.
throws:
when we are throwing any checked exception in a method and not handling it, then we need to use throws keyword in method signature to let caller program know the exceptions that might be thrown by the method.
The caller method might handle these exceptions or propagate it to its caller method using throws method. We can provide multiple exceptions in the throws clause and it can be used with main() method also.
try-catch:
We use try catch block for exception handling in our code. try is the start of the block and catch is at the end of try block to handle the exceptions.
We can have multiple catch blocks with a try and try catch block can be nested also. Catch block requires a parameter that should be of Type Exception
finally:
finally block is optional and can be used only with try catch block.
Since exception halts the process of execution, we might have some resources open that will not get closed, so we can use fin
Question: 2
What is the use of the finally block?
Finally is the block of code that is always executed even when an exception has occurred.
Question: 3
What is null pointer exception?
A null pointer exception is thrown when calling the instance method of a null object, accessing or modifying the field of a null object etc.
Question: 4
When arithmetic exception is thrown?
The Arithmetic Exception is thrown when integer is divided by zero or taking the remainder of a number by zero. It is never thrown in floating point operations.
Question: 5
Can an exception be rethrown?
Yes, an exception can be rethrown.
1000+ TNPSC Group 1 Previous Year Question Paper Pdf More
1000+ TNPSC Chemistry Study Materials Pdf More
TNPSC Group 1 Last 10 Years Question Papers with Answers Pdf More
1000+ General English Quiz Questions and Answers Pdf More
5001+ General English MCQ for Competitive Exam Pdf More
List of Thermal, Atomic, Nuclear Power Plants/Projects in India Pdf More
1000+ CAD/CAM Objective Questions and Answers Pdf More
Data structure Question Paper with Answers Pdf More
Top 100+ Ancient Indian History Quiz Questions and Answers More
Electrical Engineering Objective Questions and Answers Pdf More