Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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



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

Post New Answer

More Core Java Interview Questions

steps to connect with Oracle Databse using TYPE-2 Jdbc driver.

3 Answers  


What is an example of a keyword?

0 Answers  


How garbage collection is done in java?

0 Answers  


Why should we use singleton pattern instead of static class?

0 Answers  


What is the difference between size and length in java?

0 Answers  


How do you print array in java?

0 Answers  


What is the difference between instanceof and isinstance?

0 Answers  


suppose string s1="rajnish"; string s2="bhaskar"; then what will be happend ?

9 Answers   Fidelity,


whats the life cycle of jsp

2 Answers   Satyam,


Given a singly linked list, find the middle of the list in a single traversal without using temporary variable.

0 Answers   Fidelity,


What an i/o filter in java programming?

0 Answers  


if i have one string class then how can you achive this class functionality of this class?

3 Answers   Fidelity, iFlex,


Categories