ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
info       Did you received any Funny E-Mails from your Friends and like to share with rest of our friends? Yeah!! you can post that stuff   HERE
Google
 
Categories  >>  Software  >>  Core Java  >>  Java J2EE  >>  Java Related
 
 


 

 
 Core Java interview questions  Core Java Interview Questions
 Advanced Java interview questions  Advanced Java Interview Questions
 Swing interview questions  Swing Interview Questions
 EJB interview questions  EJB Interview Questions
 Servlets interview questions  Servlets Interview Questions
 Struts interview questions  Struts Interview Questions
 JDBC interview questions  JDBC Interview Questions
 JMS interview questions  JMS Interview Questions
 SunOne interview questions  SunOne Interview Questions
 J2EE interview questions  J2EE Interview Questions
 Weblogic interview questions  Weblogic Interview Questions
 Websphere interview questions  Websphere Interview Questions
 Java Networking interview questions  Java Networking Interview Questions
 Java J2EE AllOther interview questions  Java J2EE AllOther Interview Questions
Question
explain me with a code snippet about the generation and
handling of null point exceptions.
 Question Submitted By :: Shiva034
I also faced this Question!!     Rank Answer Posted By  
 
  Re: explain me with a code snippet about the generation and handling of null point exceptions.
Answer
# 1
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
G.arun
 

 
 
 
Other Core Java Interview Questions
 
  Question Asked @ Answers
 
what is mutability?which one is mutable String or StringBuffer?and why?give examples of each which shows the mutability of each String or StringBuffer  2
AWT event listeners extends what interface?  1
what is the difference between AWT and SWING what is the advantage of using swing?  3
Does a class inherit the constructor of its super class?if it does, how can you hide that constructor? if it doesnot how can you call it from the sub class?  1
Name the runtime exceptions that occurs frequently?  4
Why null interfaces are used in Java?  2
What is Ideal Design of Class?  2
Name the methods in mouse listeners ?  3
static inner classes means..?  1
Package1 and Package2 both have a method name lets say "methodA" with different implementation. When I import both the packages in a java class how can I use both the methods? Ericsson3
where u use Abstraction and Interface in real time Sonata2
In the HashMap, we know the values but we dont know the key, then how can we get the key from HashMap ????? Kanbay3
what is a package?  8
Howmany address lines are required to addressing 1 MB memory?  3
What is the difference between the >> and >>> operators?  1
what is difference between colection and collections? Tech-Mahindra8
How to access a method that it declared as protected?  3
What is the difference between throw and throws?  5
What is a default package ?  7
whats the life cycle of jsp Satyam10
 
For more Core Java Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com