Exceptions Questions https://www.journaldev.com/2167/java-exception-interview-questionsand-answers https://www.baeldung.com/java-exceptions-interview-questions https://javaconceptoftheday.com/java-exception-handling-interviewquestions-and-answers/ https://www.geeksforgeeks.org/java-exception-handling-question-1/ https://www.javamadesoeasy.com/2015/05/exceptions-top-60- interview-questions_16.html https://www.journaldev.com/2167/java-exception-interview-questionsand-answers 1. What is Exception in Java? 2. What are the Exception Handling Keywords in Java? 3. Explain Java Exception Hierarchy? 4. What are important methods of Java Exception Class? 5. Explain Java 7 ARM Feature and multi-catch block? 6. What is difference between Checked and Unchecked Exception in Java? 7. What is difference between throw and throws keyword in Java? 8. How to write custom exception in Java? 9. What is OutOfMemoryError in Java? 10. What are different scenarios causing Exception in thread main? 11. What is difference between final, finally and finalize in Java? 12. What happens when exception is thrown by main method? 13. Can we have an empty catch block? 14. Provide some Java Exception Handling Best Practices? 15. What is the problem with below programs and how do we fix it? https://www.baeldung.com/java-exceptions-interview-questions What is an exception? What is the purpose of the throw and throws keywords?
How can you handle an exception? How can you catch multiple exceptions? What is the difference between a checked and an unchecked exception? What is the difference between an exception and error? What exception will be thrown executing the following code block? Integer[][] ints = 1, 2, 3, null, 7, 8, 9 ; System.out.println("value = " + ints[1][1].intvalue()); What is exception chaining? What is a stacktrace and how does it relate to an exception? Why would you want to subclass an exception? What are some advantages of exceptions? Can you throw any exception inside a lambda expression s body? What are the rules we need to follow when overriding a method that throws an exception? Will the following code compile?
void dosomething() //... throw new RuntimeException(new Exception("Chained Exception")); Is there any way of throwing a checked exception from a method that does not have a throws clause? https://javaconceptoftheday.com/java-exception-handling-interviewquestions-and-answers/ What is an exception? How the exceptions are handled in java? OR Explain exception handling mechanism in java? What is the difference between error and exception in java? Can we keep other statements in between, catch and finally blocks? Can we write only block without catch and finally blocks? There are three statements in a block statement1, statement2 and statement3. After that there is a catch block to catch the exceptions occurred in the block. Assume that exception has occurred in statement2. Does statement3 get executed or not? What is unreachable catch block error? Explain the hierarchy of exceptions in java? What are run time exceptions in java. Give example? What is OutOfMemoryError in java? What are checked and unchecked exceptions in java? What is the difference between ClassNotFoundException and NoClassDefFoundError in java Can we keep the statements after finally block If the control is returning from the finally block itself? Does finally block get executed If either or catch blocks are returning the control? Can we throw an exception manually? If yes, how? What is Re-throwing an exception in java? What is the use of throws keyword in java? What is the difference between final, finally and finalize in java? How do you create customized exceptions in java? What is ClassCastException in java? What is the difference between throw, throws and throwable in java? What is StackOverflowError in java? Can we override a super class method which is throwing an unchecked exception with checked exception in the sub class? What are chained exceptions in java? Which class is the super class for all types of errors and exceptions in java? What are the legal combinations of, catch and finally blocks? What is the use of printstacktrace() method? Give some examples to checked exceptions? Give some examples to unchecked exceptions?
https://www.geeksforgeeks.org/java-exception-handling-question-1/ Predict the output of following Java program class Main public static void main(string args[]) throw 10; catch(int e) System.out.println("Got the Exception " + e); (A) Got the Exception 10 (B) Got the Exception 0 (C) Compiler Error class Test extends Exception class Main public static void main(string args[]) throw new Test(); catch(test t) System.out.println("Got the Test Exception"); finally System.out.println("Inside finally block "); (A) Got the Test Exception Inside finally block (B) Got the Test Exception (C) Inside finally block (D) Compiler Error Output of following Java program?
class Main public static void main(string args[]) int x = 0; int y = 10; int z = y/x; (A) Compiler Error (B) Compiles and runs fine (C) Compiles fine but throws ArithmeticException exception class Base extends Exception class Derived extends Base public class Main public static void main(string args[]) // some other stuff // Some monitored code throw new Derived(); catch(base b) System.out.println("Caught base class exception"); catch(derived d) System.out.println("Caught derived class exception"); (A) Caught base class exception (B) Caught derived class exception (C) Compiler Error because derived is not throwable (D) Compiler Error because base class exception is caught before derived class class Test public static void main (String[] args) int a = 0; System.out.println ("a = " + a + "\n"); int b = 20 / a; System.out.println ("b = " + b); catch(arithmeticexception e) System.out.println ("Divide by zero error"); finally System.out.println ("inside the finally block");
(A) Compile error (B) Divide by zero error (C) a = 0 Divide by zero error inside the finally block (D) a = 0 (E) inside the finally block class Test public static void main(string[] args) int a[]= 1, 2, 3, 4; for (int i = 1; i <= 4; i++) System.out.println ("a[" + i + "]=" + a[i] + "\n"); catch (Exception e) System.out.println ("error = " + e); catch (ArrayIndexOutOfBoundsException e) System.out.println ("ArrayIndexOutOfBoundsException"); (A) (B) (C) (D) (E) Compiler error Run time error ArrayIndexOutOfBoundsException Error Code is printed Array is printed Predict the output of the following program. class Test String str = "a"; void A()
str +="b"; B(); catch (Exception e) str += "c"; void B() throws Exception str += "d"; C(); catch(exception e) throw new Exception(); finally str += "e"; str += "f"; void C() throws Exception throw new Exception(); void display() System.out.println(str); public static void main(string[] args) Test object = new Test(); object.a(); object.display(); (A) (B) (C) Abdef Abdec abdefc Predict the output of the following program.
class Test int count = 0; void A() throws Exception count++; count++; count++; throw new Exception(); catch(exception ex) count++; throw new Exception(); catch(exception ex) count++; catch(exception ex) count++; void display() System.out.println(count); public static void main(string[] args) throws Exception Test obj = new Test(); obj.a(); obj.display(); (A) 4 (B) 5 (C) 6 (D) Compilation error
https://www.javamadesoeasy.com/2015/05/exceptions-top-60- interview-questions_16.html What is exception in java? Explain exception hierarchy in java?
What are differences between checked and unchecked exceptions in java? What are 5 exception handling keywords in java? Explain what is Error in java? What are differences between Exception and Error in java? Explain throw keyword in java? Explain throws keyword in java? What is difference between throw and throws in java? How to create user defined checked and unchecked Exception in java? How to use -catch-finally in java? Can we use,catch or finally block alone in java? Is it allowed to use multiple catch block in java? What is Automatic resource management in java 7? Explain -with-resource in java? Now, question comes why we need not to close file when we are using Try-with-resources in java? Explain finally keyword in java? Is it allowed to use nested -catch in java?
Discuss which checked and unchecked exception can be thrown/declared by subclass method while overriding superclass method in java? What will happen when catch and finally block both return value, also when and finally both return value in java? What is exception propagation in java?
Can a catch or finally block throw exception in java? Why shouldn t you use Exception for catching all exceptions in java? What is Difference between multiple catch block and multi catch syntax? Can a method be overloaded on basis of exceptions in java? Mention few exception handling best practices in java? Difference between Final, Finally and Finalize in java? What are the differences between between ClassNotFoundException and NoClassDefFoundError in java? What are the most important frequently occurring Exception and Errors which you faced in java?