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

What is the basic concept of java?

772


What is ellipsis in java?

815


Is jdk required on each machine to run a java program?

1009


What is a method header?

771


What is javac used for?

698


Do I need java on my computer?

738


What is function and method in java?

725


Can list contain null in java?

875


How are java objects passed to a method and what are native methods?

828


What is the collections api?

778


In how many ways we can create threads in java?

858


What is fail fast in java?

788


Why do we need singleton class?

736


What is the difference between a loader and a compiler?

742


What is the new line character?

835