---
title: "Explain the difference between checked and unchecked exceptions in Java."  
description: "Explain the difference between checked and unchecked exceptions in Java."  
author: "Steilla Mitchel"  
published: 2023-07-23  
updated: 2023-07-24  
canonical: https://www.mindstick.com/forum/159233/explain-the-difference-between-checked-and-unchecked-exceptions-in-java  
category: "java"  
tags: ["exception handling", "java", "exception"]  
reading_time: 3 minutes  

---

# Explain the difference between checked and unchecked exceptions in Java.

[Explain the difference](https://www.mindstick.com/forum/156125/can-you-explain-the-difference-between-organic-and-paid-results) between [checked and unchecked exceptions](https://www.mindstick.com/forum/160107/explain-the-difference-between-checked-and-unchecked-exceptions-in-dot-net-core) in Java.

## Replies

### Reply by Aryan Kumar

Sure, here's the [difference between checked](https://www.mindstick.com/forum/158620/explain-the-difference-between-checked-and-unchecked-exceptions-in-c-sharp) and unchecked [exceptions](https://www.mindstick.com/interview/22871/define-predifined-generic-exceptions) in Java:

In Java, there are two types of exceptions: checked and unchecked.

Checked exceptions are exceptions that are declared in the method signature. This means that the method must either handle the exception or declare that it throws the exception.

Unchecked exceptions are exceptions that are not declared in the method signature. This means that the method does not have to handle the exception.

Here's a table that summarizes the difference between checked and unchecked exceptions in Java:

| Feature | Checked exception | Unchecked exception |
| --- | --- | --- |
| Declared in the method signature | Yes | No |
| Must be handled or declared in the method signature | Yes | No |
| Examples | FileNotFoundException, ClassNotFoundException, SQLException | ArithmeticException, NullPointerException, ArrayIndexOutOfBoundsException |

Here are some examples of checked exceptions:

- FileNotFoundException: This exception is thrown when a file cannot be found.
- ClassNotFoundException: This exception is thrown when a class cannot be found.
- SQLException: This exception is thrown when an error occurs in a database operation.

Here are some examples of unchecked exceptions:

- ArithmeticException: This exception is thrown when an arithmetic operation results in an error.
- NullPointerException: This exception is thrown when a reference to an object is null.
- ArrayIndexOutOfBoundsException: This exception is thrown when an array index is out of bounds.

Checked exceptions are usually caused by errors that the programmer can prevent. For example, a programmer can prevent a FileNotFoundException by ensuring that the file exists before opening it. Unchecked exceptions are usually caused by errors that the programmer cannot prevent. For example, an ArithmeticException can occur if the user enters an invalid number.

Checked exceptions are important because they can help to prevent errors in your code. By handling checked exceptions, you can ensure that your code is robust and reliable. Unchecked exceptions are not as important as checked exceptions, but they can still cause problems in your code. It is a good idea to handle unchecked exceptions as well, but it is not as critical as handling checked exceptions.

Here are some additional things to keep in mind about checked and unchecked exceptions:

- Checked exceptions are checked at compile time. This means that the compiler will check for the checked exceptions and will not allow the code to compile if the checked exceptions are not handled or declared.
- Unchecked exceptions are not checked at compile time. This means that the compiler will not check for the unchecked exceptions and the code will compile even if the unchecked exceptions are not handled.

By following these guidelines, you can ensure that your code is properly handling exceptions.


---

Original Source: https://www.mindstick.com/forum/159233/explain-the-difference-between-checked-and-unchecked-exceptions-in-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
