Checked Vs unchecked Exceptions with example in Java Interview Questions and Answers | Code Decode

preview_player
Показать описание
Difference between checked and unchecked exception is very commonly asked java interview questions in every interview

Udemy Course of Code Decode on Microservice k8s AWS CICD link:

Course Description Video :

Difference between checked vs unchecked exceptions

Checked
Unchecked Exceptions
Another name
Checked exceptions are checked by the Java compiler so they are called compile time exceptions.
Unchecked exceptions are not checked by the compiler. These are called runtime exceptions.
When
Checked exceptions occur at compile time.
Unchecked exceptions occur at runtime.
Handled by
These types of exceptions can be handled at the time of compilation.
These types of exceptions cannot be catched or handled at the time of compilation, because they get generated by the mistakes in the program.
Handling
Must be handled in a try-and-catch block, or be thrown by the invoking method
Exception handling semantics are not required

Difference between checked vs unchecked exceptions

Checked
Unchecked Exceptions
Force
Java compiler forces us to handle these exceptions in some manner
A method is not forced by the compiler to declare the unchecked exceptions into the method declaration.
Hierarchy
They are all subclasses of Exception.
They are all subclasses of RuntimeException.
Scenario

Checked Exception represent scenario with higher failure rate

UnChecked Exception are mostly programming mistakes.
Throws clause
The throws clause on a method header must be included for checked exceptions that are not caught and handled in the method.
The throws clause on a method header is not mandatory


Checked
Unchecked Exceptions
Examples
File Not Found Exception
No Such Field Exception
Interrupted Exception
No Such Method Exception
Class Not Found Exception

No Such Element Exception
Undeclared Throwable Exception
Empty Stack Exception
Arithmetic Exception
Null Pointer Exception
Array Index Out of Bounds Exception

Hibernate Interview Questions and Answers:

Spring Boot Interview Questions and Answers:

Subscriber and Follow Code Decode

#exceptions #java #codedecode
Рекомендации по теме
Комментарии
Автор

How nicely explained. No need to go anywhere now to know what are checked and unchecked exceptions. Thanks. Keep it up

parag
Автор

Correct me if I am wrong - All exceptions occur at runtime. The only difference is Java compiler checks probable places in code for checked exceptions and forces developers to handle them.

Aniruddhdwivedi
Автор

All Exceptions are handled at run time. It is not very much correct to say compile time Exceptions. Instead checked Exceptions are those which occur at run time only but compiler checks if it is handled by the developer or not. Checking is done at compile time for checked exceptions but occurring of Exceptions are always run time only.

SaeedAhmed-glxn
Автор

Hi Code Decode, I really appreciate your efforts & your content is helping me a lot during interviews recently I have get some interesting questions if possible can you cover those as well?
1.characteristics of rest web services
2.what is  Richardson Maturity Model?

ShivaniDiware
Автор

Could u please make videos on executor and fork and join framework concepts in multithreading...

sambayeti
Автор

Hi, first of all thank you so much! Can we get notes for all the videos?

nikitasarda
Автор

Mam please tell me can we create both type of exception in java?

yourvoices