Skip to main content

Java Booleans

Boolean data type are capable to store true and false value. Generally all comparing and relational operator are produce boolean result. boolean keyword are used to define Boolean data type variables.

public class Result{
  public static void main(String[] args) {
    //Define boolean variables
    boolean isTrue=true;
    boolean isFalse=false;

    //Display boolean variable value

There are many operation which is generate boolean value. That is based on comparison operation.

public class Result{
  public static void main(String[] args) {
    //Basic operation which are produce an boolean value
    System.out.println(true^true); //false
    System.out.println(5>3); //true
    System.out.println(true!=false); //true
    System.out.println(true==false); //false

Java.lang.Boolean Class

Methods which is publicly used by Boolean wrapper class.

Method Syntax
equals public boolean java.lang.Boolean.equals(java.lang.Object)
toString public java.lang.String java.lang.Boolean.toString()
toString public static java.lang.String java.lang.Boolean.toString(boolean)
hashCode public static int java.lang.Boolean.hashCode(boolean)
hashCode public int java.lang.Boolean.hashCode()
compareTo public int java.lang.Boolean.compareTo(java.lang.Boolean)
compareTo public int java.lang.Boolean.compareTo(java.lang.Object)
getBoolean public static boolean java.lang.Boolean.getBoolean(java.lang.String)
booleanValue public boolean java.lang.Boolean.booleanValue()
valueOf public static java.lang.Boolean java.lang.Boolean.valueOf(java.lang.String)
valueOf public static java.lang.Boolean java.lang.Boolean.valueOf(boolean)
compare public static int,boolean)
parseBoolean public static boolean java.lang.Boolean.parseBoolean(java.lang.String)
logicalAnd public static boolean java.lang.Boolean.logicalAnd(boolean,boolean)
logicalOr public static boolean java.lang.Boolean.logicalOr(boolean,boolean)
logicalXor public static boolean java.lang.Boolean.logicalXor(boolean,boolean)
wait public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException
wait public final native void java.lang.Object.wait(long) throws java.lang.InterruptedException
wait public final void java.lang.Object.wait() throws java.lang.InterruptedException
getClass public final native java.lang.Class java.lang.Object.getClass()
notify public final native void java.lang.Object.notify()
notifyAll public final native void java.lang.Object.notifyAll()
public class Test{
    public static void main(String[] args){
      Boolean b1=true,b2=false;



Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment