- On
- By
- 0 Comment
- Categories: keyword, Keyword in Java
The boolean keyword in Java programming language
The boolean keyword in java programming language
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;
Declare a boolean variable
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
Declare a boolean method
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