Top 1000+ Advanced Java Interview Questions 2020-2021 - 1
What are the exception handling keyword in java?
There are four keywords used in java exception handling.
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.
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.
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 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
What is the use of the finally block?
Finally is the block of code that is always executed even when an exception has occurred.
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.
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.
Can an exception be rethrown?
Yes, an exception can be rethrown.
7000+ Gate Computer Science Engineering Previous Year Questions More
7000+ Fill in the Blanks with Suitable Homonyms More
7000+ Fill in the Blanks with Suitable Homophones More
Power Semiconductor Device and Integrated Circuits MCQ Questions Pdf More
7000+ Synonyms, Antonyms Questions for SSC CGL Pdf More
Top 50+ .Net Interview Questions and Answers More
Computer MCQ for Competitive Exams More
1000+ General Knowledge Questions and Answers in English More
100+ PL/SQL Interview Questions and Answers for Experienced More
Active and Passive Voice Practice Test More