concept true in category java

This is an excerpt from Manning's book Java SE 11 Programmer I Certification Guide.
A boolean variable can store one of two values: true or false. It is used in scenarios where only two states can exist.Here’s some code that defines boolean primitive variables:
Table 6.1 Operator types and the relevant operators
Operator type
Operators
Purpose
Assignment
=, +=, -=, *=, /=,%=
Assign value to a variable
Arithmetic
+, -, *, /, %, ++, --
Add, subtract, multiply, divide, modulus, increment and decrement primitives. + can be also used to concatenate String values.
Relational
<, <=, >, >=, ==, !=
Compare primitives
Logical
!, &&, ||
Apply NOT, AND, and OR logic to primitives
Note Not all operators can be used with all types of operands. For example, you can determine whether a number is greater than another number, but you can’t determine whether true is greater than false or a number is greater than true.
The && operator returns true only if both the operands are true. If the first operand to this operator evaluates to false, the result can never be true. Therefore, && does not evaluate the second operand. Similarly, the || operator does not evaluate the second operator if the first operand evaluates to true.
int marks = 8; int total = 10; System.out.println(total < marks && ++marks > 5); #1 System.out.println(marks); #2 System.out.println(total == 10 || ++marks > 10); #3 System.out.println(marks); #4In the first print statement #1, because the first condition, total < marks, evaluates to false, the next condition, ++marks > 5, isn’t even evaluated. As you can see #2, the output value of marks is still 8 (the value to which it was initialized on line 1)! Similarly, in the next comparison #3, because total == 10 evaluates to true, the second condition, ++marks > 10, isn’t evaluated. Again, this can be verified when the value of marks is printed again #4, and the output is 8.

This is an excerpt from Manning's book Java Testing with Spock.
Groovy treats all objects[8] as true unless

This is an excerpt from Manning's book OCA Java SE 8 Programmer I Certification Guide.
Explanation: Both of the short-circuit operators, && and ||, will evaluate their first operand. For the short-circuit operator &&, if the first operand evaluates to false, it won’t evaluate the second operator. For the short-circuit operator ||, if the first operand evaluates to true, it won’t evaluate the second operator.
Code will print true if code on line 6 is modified to the following: boolean returnVal = (num1 >= 12 && num2 < 4.567) || eJavaResult == true;
An if construct enables you to execute a set of statements in your code based on the result of a condition. This condition must always evaluate to a boolean or a Boolean value. You can specify a set of statements to execute when this condition evaluates to true or false. (In many Java books, the terms constructs and statements are used interchangeably.)
Let’s quickly go through the code used in figure 5.2’s if, if-else, and if-else-if-else statements. In the following example code, if the condition name.equals("Lion") evaluates to true, a value of 200 is assigned to the variable score:
![]()
In the following example, if the condition name.equals("Lion") evaluates to true, a value of 200 is assigned to the variable score. If this condition were to evaluate to false, a value of 300 would be assigned to the variable score:
Explanation: The condition specified in the do-while loop evaluates to false (because 10<2 evaluates to false). But the control enters the do-while loop because the do-while loop executes at least once—its condition is checked at the end of the loop. The while loop evaluates to true for the first iteration and adds 20 to i, making it 30. The while loop doesn’t execute for the second time. Hence, the value of the variable i at the end of the execution of the previous code is 30.