Top Ten Exceptions in Java?
>> Sunday, May 22, 2011
- Null Pointer Exception Exception
EXAMPLE:
String s-null;
2.Stack Overflow error
If we are performing recursive method invocation
Example:
class Test{
public void m1()
{
m1();
}
public static void main(String args[])
{
m1();
}
}
3.ArrayIndexOutOfBound Exception
If we are assigning a value to an array which is out of it's range
EXAMPLE:
int[] a={10,20,89,60}
System.out.println(a[2]); o/p is==89;
System.out.println(a[5]); o/p AIOBE;
4.) ClassCastException
It occurs when we are trying to typecast parent class object to child type
5.) NoclassDefFoundError
If the required class is not found available
Ex:
Java A and enter
If a.class file is not available we will get NCDFE
6.ExceptionInInitializerError
Whenever an Exception occurred during Initialization of static variables (or) static blocks.
EX:
class Test
{
static int i=10/0;
}
output :
EIIE caused by AritmeticException/by Zero
7.)IllegalArgumentException
If we are trying to invoke set priority method with more than it's range
EX:
class Test{
public static void main(String args[])
{
Thread.currentThread.setPriority(100);
}
}
8.) NumberFormatException
We are attempting to convert string to number type,if string is not formatted properly
EX:
String s="10";
int i=Integer.parseInt(s) o/p===10;
String s="ten";
int i=Integer.parseInt(s); o/p is NFE
9.)IllegalStae Exception
If thread is started and we again start the thread it raises ISE
10.)Assertion Exception
0 comments:
Post a Comment