This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Mock Exam Errata and the fly likes Eddie McNally's Jxam question... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "Eddie McNally Watch "Eddie McNally New topic
Author

Eddie McNally's Jxam question...

Brett Hicks
Greenhorn

Joined: Oct 11, 2001
Posts: 1
Question from the test...
Given the following code snippet:
String s = null;
Which of the following will throw NullPointerException...
1) if (( s!= null ) & ( s.length() > 0 ))
2) if (( s!= null ) && ( s.length() > 0 ))
3) if (( s!= null ) | ( s.length() > 0 ))
4) if (( s!= null ) | | ( s.length() > 0 ))
5) none of the above
The answer says that 1,2,3 & 4 will cause NullPointerExceptions.
Shouldn't number 2 short-circuit before it hits the s.length() statement, and thusly leave 1, 3 & 4 as the correct answers.

Nain Hwu
Ranch Hand

Joined: Sep 16, 2001
Posts: 139
Brett,
You are right - 2 will not cause NullPointerException.
 
Don't get me started about those stupid light bulbs.
 
subject: Eddie McNally's Jxam question...
 
Similar Threads
Confusion
another Mock Exam Question
JXAM question on string and logical operators
When does a NullPointerException occurs?
Exception question