Home Javatutorials boolean comparisons - tutorial



boolean comparisons - tutorial
Posted on: April 18, 2011 at 12:00 AM
boolean comparisons - tutorial

Boolean Data Type

Boolean data types can acquire two values either true or false. We use these data types when we need to track the true/ false condition.

The condition are denoted by these two key words- true(for true condition) & false(for false condition).

Control Statement and Boolean

The  control statements like if, for, while and do all requires boolean value to execute. Generally operators are used to evaluate a condition, which return boolean value. According to this boolean value, the control statements executes.

The given below example will give you a clear idea :

package com.roseindia;

public class BooleanExample {
public static void main(String[] arg) {
boolean bool = true;
System.out.println("Value of bool : " + bool);
if (bool == true) {
System.out.println("Value of boolean is true.");
} else {
System.out.println("Value of boolean is false.");
}
}
}

Comparison Operator

The comparison operator is used to compare the two primitive values. The given below the operator, their name and their output :

Operator Name Output
i < j less than true/false
i<=j less than or equal true/false
i = = j equal true/false
i >= j greater than equal true/false
i > j greater than true/false
i != j not equal true/false

Logical Operators

Given below the logical operator and their meaning :

Operator Name Meaning
a && b and If both a & b are true, the result is true.
a || b or If either a or b are true, the result is true
!a not true when 'a' is false, and false when 'a' is true.

Methods which return Boolean values

In java, there are many methods which returns Boolean value. For example, equals, instanceof operators, the methods whose name starts with "is" etc.

Related Tags for boolean comparisons - tutorial:


More Tutorials from this section

Ask Questions?    Discuss: boolean comparisons - tutorial  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.