explain me with a code snippet about the generation and
handling of null point exceptions.
Answer / 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 |
steps to connect with Oracle Databse using TYPE-2 Jdbc driver.
What is an example of a keyword?
How garbage collection is done in java?
Why should we use singleton pattern instead of static class?
What is the difference between size and length in java?
How do you print array in java?
What is the difference between instanceof and isinstance?
suppose string s1="rajnish"; string s2="bhaskar"; then what will be happend ?
whats the life cycle of jsp
Given a singly linked list, find the middle of the list in a single traversal without using temporary variable.
What an i/o filter in java programming?
if i have one string class then how can you achive this class functionality of this class?