This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Qn about boolean & operator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Qn about boolean & operator" Watch "Qn about boolean & operator" New topic
Author

Qn about boolean & operator

Kishore Dandu
Ranch Hand

Joined: Jul 10, 2001
Posts: 1934
Does it work similar to using &&.

I mean is a & b same as a&&b; in case both a, b are boolean


Kishore
SCJP, blog
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
No, in the case of &&, if expression a is false then expression b will not even be evaluated.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
A common use of &&:

if ( myObject != null && myObject.isSomething() ) { ... }

if myObject contains null, you are guaranteed that no attempt will be made to invoke myObject.isSomething()

If you use & instead of && in those circumstances, you'd get a NullPointerException


Mike Gershman
SCJP 1.4, SCWCD in process
 
wood burning stoves
 
subject: Qn about boolean & operator