1) The divergence betwixt checked as well as unchecked Exception inward Java?
For checked exceptions, the compiler ensures that they are either handled using try-catch, try-finally or try-catch-finally block or thrown away. If a method, which throws a checked exception e.g IOException as well as doesn't handgrip them or doesn't declare them inward throws degree of method, a compile-time fault volition occur. On the other hand, the compiler doesn't do similar checks for an unchecked exception, that's why it is known every bit un-checked. These are too called runtime exception because they extend java.lang.RuntimeException.
There is or thus other divergence betwixt checked as well as unchecked exception, checked exceptions are those exception classes, which are a subclass of java.lang.Exception simply non of java.lang.RuntimeException, on the other hand, the unchecked exception e'er extends RuntimeException.
Some of the well-known examples of checked exceptions are IOException, SQLException, ParseException, etc, spell java.lang.ArrayIndexOutOfBoundsException, IllegalArgumentException and java.lang.NullPointerException has most seen examples of unchecked exception inward Java. See my post checked vs runtime exception for to a greater extent than differences.
2) What is the divergence betwixt throw as well as throws inward Java? (answer)
3) Difference betwixt finally, finalize as well as finalizer inward Java? (answer)
4) What happens when a Thread gets uncaught exception? (answer)
5) Does in conclusion runs always? On which instance in conclusion doesn't run? (answer)
6) What is try-with-resource or automatic resources management? (answer)
7) How to teach a electrical current stack draw of a Thread? (answer)
8) Difference betwixt Error as well as Exception inward Java? (answer)
9) Difference betwixt NoClassDefFoundError as well as ClassNotFoundException inward Java? (answer)
10) What is chaining of Exception? (answer)
11) How to do custom Exceptions inward Java? (answer)
12) Can nosotros accept a endeavour block without a catch? (answer)
13) What are the 5 keywords used inward Exception handling? (answer)
14) Can y'all pick out receive got of Error similar java.lang.OutOfMemoryError inward Java? (answer)
15) What is the occupation amongst the below code?
Output:
This plan volition non compile as well as give y'all the fault “The exception FileNotFoundException is already caught past times the option IOException”, because FileNotFoundException is a subclass of IOException.
There are 2 ways to solve this occupation :
1) Use Simple Catch Block as well as handgrip FileNotFoundException earlier IOException
2) Only handgrip IOException instead of both FileNotFoundException as well as IOException.
You tin farther see answer)
23) What are or thus of the best practices y'all follow spell treatment Errors as well as Exception inward Java? (answer)
24) What are the pros as well as cons of catching Throwable or Error? (answer)
That's all close or thus frequently asked Java Exception interview questions. See, how many questions y'all tin reply from this list. I'll post the reply afterward simply if y'all know the reply y'all tin e'er part on the comments section.
Further Learning
Complete Java Masterclass
see here)10 Great XML Interview Questions for Java Programmers (read here) 50+ Data Structure as well as Algorithms Interview Questions (questions) 20 Great Java Design Pattern Questions asked on Interviews (see here) 10 pop Struts Interview Questions for Java developers (list) 20+ String Coding Problems from Interviews (questions) 10 oft asked Servlet Interview Questions amongst Answers (see here) Top 10 JSP Questions from J2EE Interviews (read here) 12 Good RESTful Web Services Questions from Interviews (read here) Top 10 EJB Interview Questions as well as Answers (see here) Top 10 JMS as well as MQ Series Interview Questions as well as Answers (list) 10 Great Hibernate Interview Questions for Java EE developers (see here) 10 Great JDBC Interview Questions for Java Programmers (questions) 15 Java NIO as well as Networking Interview Questions amongst Answers (see here) 15 Data Structure as well as Algorithm Questions from Java Interviews (read here) Top 10 Trick Java Interview Questions as well as Answers (see here) Top forty Core Java Phone Interview Questions amongst answers (list)
Thanks a lot for reading this article, if y'all similar this article thus delight part amongst your friends as well as colleagues. If y'all accept whatever questions or feedback, delight drib a note.
For checked exceptions, the compiler ensures that they are either handled using try-catch, try-finally or try-catch-finally block or thrown away. If a method, which throws a checked exception e.g IOException as well as doesn't handgrip them or doesn't declare them inward throws degree of method, a compile-time fault volition occur. On the other hand, the compiler doesn't do similar checks for an unchecked exception, that's why it is known every bit un-checked. These are too called runtime exception because they extend java.lang.RuntimeException.
There is or thus other divergence betwixt checked as well as unchecked exception, checked exceptions are those exception classes, which are a subclass of java.lang.Exception simply non of java.lang.RuntimeException, on the other hand, the unchecked exception e'er extends RuntimeException.
Some of the well-known examples of checked exceptions are IOException, SQLException, ParseException, etc, spell java.lang.ArrayIndexOutOfBoundsException, IllegalArgumentException and java.lang.NullPointerException has most seen examples of unchecked exception inward Java. See my post checked vs runtime exception for to a greater extent than differences.
2) What is the divergence betwixt throw as well as throws inward Java? (answer)
3) Difference betwixt finally, finalize as well as finalizer inward Java? (answer)
4) What happens when a Thread gets uncaught exception? (answer)
5) Does in conclusion runs always? On which instance in conclusion doesn't run? (answer)
6) What is try-with-resource or automatic resources management? (answer)
7) How to teach a electrical current stack draw of a Thread? (answer)
8) Difference betwixt Error as well as Exception inward Java? (answer)
9) Difference betwixt NoClassDefFoundError as well as ClassNotFoundException inward Java? (answer)
10) What is chaining of Exception? (answer)
11) How to do custom Exceptions inward Java? (answer)
12) Can nosotros accept a endeavour block without a catch? (answer)
13) What are the 5 keywords used inward Exception handling? (answer)
14) Can y'all pick out receive got of Error similar java.lang.OutOfMemoryError inward Java? (answer)
15) What is the occupation amongst the below code?
import java.io.FileNotFoundException; import java.io.IOException; public class ExceptionInterviewQuestion_01 { public static void main(String[] args) { try { multiple(); } catch (FileNotFoundException | IOException ex) { e.printStackTrace(); } } public static void multiple() throws IOException, FileNotFoundException{ System.out.println("Inside multiple"); } }
Output:
This plan volition non compile as well as give y'all the fault “The exception FileNotFoundException is already caught past times the option IOException”, because FileNotFoundException is a subclass of IOException.
There are 2 ways to solve this occupation :
1) Use Simple Catch Block as well as handgrip FileNotFoundException earlier IOException
try { multiple(); }catch(FileNotFoundException ex){ ex.printStackTrace(); }catch (IOException e) { ex.printStackTrace(); }
2) Only handgrip IOException instead of both FileNotFoundException as well as IOException.
try { multiple(); }catch (IOException e) { ex.printStackTrace(); }
You tin farther see answer)
23) What are or thus of the best practices y'all follow spell treatment Errors as well as Exception inward Java? (answer)
24) What are the pros as well as cons of catching Throwable or Error? (answer)
That's all close or thus frequently asked Java Exception interview questions. See, how many questions y'all tin reply from this list. I'll post the reply afterward simply if y'all know the reply y'all tin e'er part on the comments section.
Further Learning
Complete Java Masterclass
see here)
Thanks a lot for reading this article, if y'all similar this article thus delight part amongst your friends as well as colleagues. If y'all accept whatever questions or feedback, delight drib a note.
No comments:
Post a Comment