explain me with a code snippet about the generation and
handling of null point exceptions.

Answer Posted / g.arun

class Test
{
public static void main(String[] args)
{
try
{
int a[] = null;
System.out.println(a.length);
}
catch (NullPointerException n)
{
System.out.println(n);
}

}
}
U can try this by changing NullPointerException in catch
block as catch(Exception e){ System.out.println(n);}

and Using throw it is

class Test
{
public static void main(String[] args)
{
int a[] = null;
System.out.println(a.length);
NullPointerException n = new NullPointerException();
throw n;
}
}

Using Throws

class Test
{
public static void main(String[] args) throws
Exception
{
int a[] = null;
System.out.println(a.length);
}
}

That's all friends hope this one helps you

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain where variables are created in memory?

782


Can finally block be used without a catch?

760


What is difference between public static and void?

715


Is java written in c?

738


What is thread synchronization in java?

677


what is thread? : Java thread

771


What is package protected in java?

747


Where import statement is used in a java program?

836


What is java and their uses?

785


What was java originally called?

727


Can we create an object of private class?

757


What is parsing a sentence?

774


Is set ordered in java?

800


Are arrays static in java?

811


Define iterator and methods in iterator?

761