Java Booleans
Java Booleans
A boolean in Java is a data type that can store only two values:
-
true -
false
Booleans are commonly used in conditions, decision making, and logical expressions.
✅ Declaring Boolean Variables
✅ Boolean Expressions (Comparison)
Boolean values are often returned from expressions involving comparison operators:
✅ Boolean with Logical Operators
| Operator | Meaning | Example |
|---|---|---|
&& |
AND | true only if both conditions are true |
|
||
! |
NOT | reverses boolean value |
Example:
✅ Boolean in If-Else
Booleans are mostly used for decision making:
🚀 Boolean Method Example
Some methods also return boolean:
⭐ Full Example
📌 Summary
| Feature | Description |
|---|---|
| Values | true, false |
| Type | Primitive |
| Common Uses | Comparisons, loops, if-else |
| Operations | Logical (&&, ` |
