What are checked and unchecked Exceptions in Java?

What are Checked Exceptions?

If you write a piece of code that is logically correct but can fail in certain scenarios then you need to handle those scenarios. So for example if you write code which reads a File and suppose at run time the File is not available then it will throw an Exception. So you can handle this by catching a FileNotFoundException.

What are Runtime Exceptions?

Suppose you write a piece of code which is logically not correct. Say you write code that does not use an API correctly then your code is buggy. So no point handling exception here. Let the error be printed in the log so that you can make corrections to the code.

The application can catch this exception, but it probably makes more sense to eliminate the bug that caused the exception to occur.

What are Errors?

When the exception is beyond your application’s scope. Like some hardware issue. Say at runtime some I/O error occurs.

Both Runtime and Error are unchecked. You don’t need to handle them.