About boolean in java

I have always seen people having problem with the boolean in Java. Boolean can be effective to compress the size of your Java program. Here I have tried to give you a simple idea about boolean to clear confusions about boolean.

What is boolean?

There are eight type of primitive data types in Java(Read detail here) . Boolean is one of those primitive data types. It can have two possible values: true and false. The values of a boolean is written with the reserver words true and false.

comparison operators:

Comparison operators are used to compare the primtive values.

Op Name Meaning
i < j less than 6 < 24 is true.
i <= j less than or equal 6 <= 24 is true.
i == j equal 6 == 24 is false.
i >= j greater than or equal 10 >= 10 is true.
i > j greater than 10 > 10 is false.
i != j not equal 6 != 24 is true.

comparison operators are also used to compare the values of booleans.

Logical operators:

Op Name Meaning
a && b and The result is true only if both a and b are true.
a || b or The result is true if either a or b is true.
!a not true if a is false and false if a is true.

Happy Programming…. 🙂

About anik

This is Anik Das. I am Student of Electrical and Electronics engineering in National Institute of Technology, Warangal (NITW). I used to study in BRAC University(BRACU) (which is one of the best part of my life). There I also studied EEE but after getting the ICCR Scholarship by the Indian Govt. I moved to NITW. I have completed my H.S.C from Notre Dame College (NDC). I used to work as Microsoft Student Partner(MSP) in Microsoft. I am a tech loving boy…I also love to know about newer and newer things. I am here to share what I learn...

Posted on March 18, 2011, in java, java program, simple java progams. Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: