Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Javatutorials boolean comparisons - tutorial

Related Tutorials


 
 

Share on Google+Share on Google+

boolean comparisons - tutorial

Advertisement
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.

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 18, 2011

Related Tutorials

Discuss: boolean comparisons - tutorial  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com