In this tutorial , We will learn about the boolean keyword in java programming language
In Java language, Boolean is used to declare a variable as a boolean type. This represents only either true or false(Zero or one).
In Java language, default boolean value is initialized with false;
Syntax
syntax of float data type declaration
boolean <variable_name> = <boolean_value>;
Example
Example for float data type declaration
boolean isSmallest=true;
The boolean keyword can be used to declare a return type of method in Java
Syntax
<access_modifier> <return_type> <method_name>; { return <method_name>; }
Example
public boolean Islargest() { return getBalance; }
Example of boolean variable with in class
public class Example _boolean{ // this is a class in java public static void main(String args[]){ // this is a main method in java } public boolean Iscorrect(){ // this is a boolean method which returns value; } }
Example
public class Boolean_Key{ public static void main(String args[]){ int age=20; boolean a=true, b=false; if(age>18){ System.out.println(a); } else{ System.out.println(a); } } }
When the above code is compiled and executed, it will produce the following results
true
There are other Java language keywords that are similar to this keyword
static keyword in Java language
extends keyword in Java language
Suggested for you
Usage of final keyword in Java
Finally keyword in Java language
s
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…
Java program to check odd or even using recursion In this tutorial, we discuss a…