boolean keyword in Java

The boolean keyword is used to declare a variable as a boolean type, which represents only either true or false.

For example:

  1. boolean isActive;
  2.  
  3. boolean isAdmin;
boolean isActive;

boolean isAdmin;


The boolean keyword can be used to declare a type of a method parameter as below:

  1. public void sendEmail(boolean isAdmin) {
  2.      
  3.  if(isAdmin){
  4.  
  5.                        //Send email only for Admin
  6.             }
  7.  
  8. }
public void sendEmail(boolean isAdmin) {
      
 if(isAdmin){

                       //Send email only for Admin
            }

}


The boolean keyword can also be used to declare return type of a method as below:

  1. public boolean isSeniorCitizen() {
  2.  
  3. if(age >=60){    
  4.                  return true;
  5.             }
  6. else{
  7.          return false;
  8.     }
  9. }
public boolean isSeniorCitizen() {

if(age >=60){    
                 return true;
            }
else{
         return false;
    }
}

About the Author

Founder of javainsimpleway.com
I love Java and open source technologies and very much passionate about software development.
I like to share my knowledge with others especially on technology 🙂
I have given all the examples as simple as possible to understand for the beginners.
All the code posted on my blog is developed,compiled and tested in my development environment.
If you find any mistakes or bugs, Please drop an email to kb.knowledge.sharing@gmail.com

Connect with me on Facebook for more updates

Share this article on