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
2
3
boolean isActive;
 
boolean isAdmin;
boolean isActive;

boolean isAdmin;


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

1
2
3
4
5
6
7
8
public void sendEmail(boolean isAdmin) {
      
 if(isAdmin){
 
                       //Send email only for Admin
            }
 
}
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
2
3
4
5
6
7
8
9
public boolean isSeniorCitizen() {
 
if(age >=60){    
                 return true;
            }
else{
         return false;
    }
}
public boolean isSeniorCitizen() {

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

About the Author

Karibasappa G C (KB)
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