java.lang.IllegalArgumentException – Reasons and How to Solve?

Here you will learn possible causes of Exception in thread “main” java.lang.IllegalArgumentException and ways to solve it. I hope you know the difference between error and exception. Error means programming mistake that can be recoverable only by fixing the application code. But exceptions will arise only when exceptional situations occurred like invalid inputs, null values, etc. They can be handled using try catch blocks. java.lang.IllegalArgumentException will raise when invalid inputs passed to the method. This is most frequent exception in java.

Read more

Java NullPointerException – Reasons for Exception and How to Fix?

In this tutorial you will learn about Java NullPointerException and ways to fix this. A runtime error that can be handled by the programmer is called an Exception. Some exceptions that are checked at compile time are called Checked Exceptions, these also called compile time errors. But the term we are using Exception only refers to Unchecked exceptions which are checked by JVM but not by compiler. Java NullPointerException Java.lang.NullPointerException is one of the most common exception in Java that

Read more

Difference between Throw and Throws in Java

In this tutorial you will learn about difference between throw and throws keywords in java with example. When we run a java program which contains errors, programmers should handle errors by exception handling (using try, catch and finally blocks) or avoid (throw) it. Otherwise JVM will give error which causes the termination of the running program and loss of data that has been processed till that line of the program. Throw and Throws are two keywords used in java syntax

Read more

Checked and Unchecked Exceptions in Java

There are two types of exceptions in Java i.e. checked and unchecked exceptions. Below I have explained about these two exceptions with examples. Checked and Unchecked Exceptions in Java Checked Exceptions Those exceptions that are checked at compilation time are called checked exceptions. Checked exception includes the classes that extend Throwable class except RuntimeException and Error. Some examples of checked exceptions are: InvocationTargetException SQLException ClassNotFoundException IOException If a method throws checked exceptions then it must handle them by try catch

Read more