Computer Science, asked by Shivam256, 1 year ago

Why do we use "||" instead of "|" in java?What is boolean in java?

Answers

Answered by AdiPCS
1
If you use the || and && forms, rather than the | and & forms of these operators, Java will not bother to evaluate the right-hand operand alone.

It's a matter of if you want to short-circuit the evaluation or not -- mostof the time you want to.

A good way to illustrate the benefits of short-circuiting would be to consider the following example.

Boolean b = true; if(b || foo.timeConsumingCall()) { //we entered without calling timeConsumingCall() }

A Boolean value is one with two choices: true or false, yes or no, 1 or 0. In Java, there is a variable type for Boolean values: booleanuser = true; So instead of typing int or double or string, you just type boolean (with a lower case "b").

AdiPCS: if you are helped then please give me brainliest
Similar questions