Register for our webinar

How to Nail your next Technical Interview

1 hour
Loading...
1
Enter details
2
Select webinar slot
*Invalid First Name
*Invalid Last Name
*Invalid Phone Number
By sharing your contact details, you agree to our privacy policy.
Select your webinar time
Step 1
Step 2
Congratulations!
You have registered for our webinar
Oops! Something went wrong while submitting the form.
1
Enter details
2
Select webinar slot
Step 1
Step 2
Confirmed
You are scheduled with Interview Kickstart.
Redirecting...
Oops! Something went wrong while submitting the form.
Iks white logo

You may be missing out on a 66.5% salary hike*

Nick Camilleri

Head of Career Skills Development & Coaching
*Based on past data of successful IK students
Iks white logo
Help us know you better!

How many years of coding experience do you have?

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Our June 2021 cohorts are filling up quickly. Join our free webinar to Uplevel your career
close
closeAbout usWhy usInstructorsReviewsCostFAQContactBlogRegister for Webinar

Attend our Free Webinar on How to Nail Your Next Technical Interview

WEBINAR +LIVE Q&A

How To Nail Your Next Tech Interview

Hosted By
Ryan Valles
Founder, Interview Kickstart
Our tried & tested strategy for cracking interviews
How FAANG hiring process works
The 4 areas you must prepare for
How you can accelerate your learnings

Checked vs Unchecked Exceptions in Java

Attend our Free Webinar on How to Nail Your Next Technical Interview

WEBINAR +LIVE Q&A

How To Nail Your Next Tech Interview

Hosted By
Ryan Valles
Founder, Interview Kickstart
Our tried & tested strategy for cracking interviews
How FAANG hiring process works
The 4 areas you must prepare for
How you can accelerate your learnings

Checked vs Unchecked Exceptions in Java

# Checked vs Unchecked Exceptions in Java Java provides a powerful and robust exception handling mechanism which allows users to handle errors and exceptions efficiently. In Java, there are two types of exceptions - checked and unchecked exceptions. Checked exceptions are those which are checked at compile-time. These exceptions are checked by the compiler to ensure that the code has appropriate exception handling. Examples of checked exceptions are IOException, SQLException, ClassNotFoundException, etc. All these exceptions are checked by the compiler at the time of compilation and the programmer needs to provide necessary code to handle the exception. Unchecked exceptions, on the other hand, are not checked by the compiler. These exceptions are not checked by the compiler at the time of compilation, but are thrown during the execution of the program. Examples of unchecked exceptions are ArithmeticException, ArrayIndexOutOfBoundsException, NullPointerException, etc. These exceptions can be handled by the programmer, but it is not compulsory. Checked exceptions are generally used to signal conditions that a reasonable application might want to catch, while unchecked exceptions are used to signal programming errors and other conditions that are outside the control of the application. It is important to understand the difference between checked and unchecked exceptions, as this will help you to handle errors and exceptions in Java effectively.

Worried About Failing Tech Interviews?

Attend our webinar on
"How to nail your next tech interview" and learn

Hosted By
Ryan Valles
Founder, Interview Kickstart
Our tried & tested strategy for cracking interviews
How FAANG hiring process works
The 4 areas you must prepare for
How you can accelerate your learnings
Register for Webinar
###Checked Exceptions in Java Checked exceptions are exceptions which are checked at compile-time. This means that the code which could potentially throw a checked exception must either handle the exception or be declared to throw the exception. This is done to ensure that the code that could potentially throw an exception is prepared to handle the exception. A simple example of a checked exception in Java is the IOException. This exception is thrown when an input/output operation fails. ###Sample Code ```java import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class CheckedExceptions { public static void main(String[] args) { BufferedReader br = null; try { br = new BufferedReader(new FileReader("file.txt")); String line = br.readLine(); while (line != null) { System.out.println(line); line = br.readLine(); } } catch (IOException e) { System.out.println("An I/O error occurred."); } finally { try { if (br != null) { br.close(); } } catch (IOException e) { System.out.println("Error closing BufferedReader."); } } } } ``` ###Unchecked Exceptions in Java Unchecked exceptions are exceptions which are not checked at compile-time. This means that the code which could potentially throw an unchecked exception does not need to handle the exception or declare it to be thrown. A simple example of an unchecked exception in Java is the NullPointerException. This exception is thrown when a reference to an object is null and the code attempts to call a method on the object. ###Sample Code ```java public class UncheckedExceptions { public static void main(String[] args) { String str = null; System.out.println(str.length()); } } ```