- Boolean is a primitive data type.
- Boolean is the smallest data type in Java which is made up of only 1 bit.
- Boolean data type represents only two possible values - True and False.
- The default Boolean value is False.
Syntax to Declare Boolean variable :
boolean <variable name> = <default value>;
Example:
boolean x = true;
boolean y = false;
Simple Sample Program Describing Boolean Data Type:
public class Main {
public static void main(String[] args) {
boolean x = true;
System.out.println("x is " + x);
int y = 5;
boolean z = (y > 15);
System.out.println("z is " + z);
}
}
Output:
x is true
z is false
The above is a simple example for Boolean data type in Java programming and click the link Primitive Data Type to learn more about other Data types in Java.
No comments:
Post a Comment