• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Null Pionter Exception

 
Ranch Hand
Posts: 321
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone please help me out to determine in which all cases the Null ponter Exception would be thrown?
String s=null;
If((s!=null) && (s.length()>0));
If((s!=null) | (s.length()>0));
If((s!=null) | | (s.length()>0));
If((s!=null) & (s.length()>0));
In my opinion only in the first case when we are using short-circuit && operator the first part evaluates to false and so the second part is not checked and hence it does not throw Null-PointerException . In all the rest of the case the second part is evaluated so it throws the NullPointerException as the string is having null value.Can some one throw some light ??
 
Enthuware Software Support
Posts: 4832
52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You reasoning is very correct.
Other 2 cases to think about are:
If((s==null) | (s.length()==0));
If((s==null) | | (s.length()==0));
-Paul.

------------------
Get Certified, Guaranteed!
(Now Revised for the new Pattern)
www.enthuware.com/jqplus
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi friend;
the correct answer is 2,3,& 4
becauase
in last forth option it will ceck both sides.so if there is not shortcircuit operators so it will check both condition.
Thanks.
Vishad Patel.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic