Java Boolean
Java Tutorial » Java Boolean
In Java, the boolean keyword it is used to store only two possible values, as:
TRUE / FALSE or
YES / NO
Its default value is "false".
Boolean data type in Java, can take one of this value: true or false.
Boolean Values, example
Type boolean is used with the boolean keyword and it can have only one of this values: true or false:
Example:
I like Java: true
It is warm in winter: false
public class Main {
public static void main(String[] args) {
boolean i_like_java = true;
boolean is_warm_in_winter = false;
System.out.println("I like Java: " + i_like_java);
System.out.println("It is warm in winter: " + is_warm_in_winter);
}
}
Output:public static void main(String[] args) {
boolean i_like_java = true;
boolean is_warm_in_winter = false;
System.out.println("I like Java: " + i_like_java);
System.out.println("It is warm in winter: " + is_warm_in_winter);
}
}
I like Java: true
It is warm in winter: false
Boolean Expression
In Java Boolean expression is an expression that returns Boolean value like: true or false.
For next esample we use an operator, as "the greater than" (>) operator to find out if an variable or expresion is true or false:
Example: use the + method
false
public class Main {
public static void main(String[] args) {
int x = 20;
int y = 18;
boolean a1 = true;
boolean a2 = false;
if (x < y) {
System.out.println(a1);
}
else
{
System.out.println(a2);
}
}
}
Output:public static void main(String[] args) {
int x = 20;
int y = 18;
boolean a1 = true;
boolean a2 = false;
if (x < y) {
System.out.println(a1);
}
else
{
System.out.println(a2);
}
}
}
false
Java Boolean default value, to string, operators, class, to int, vs boolean, null, ejemplo, array, type, true false, method
Java Boolean - java
Online Editor
This tool makes it easy to create, adjust, and experiment with custom colors for the web.
HTML Templates

Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.
CSS HTML Layout

Find here examples of creative and unique website layouts.
Free CSS HTML Menu

Find here examples of creative and unique website CSS HTML menu.