- On
- By
- 0 Comment
- Categories: If block, Keyword in Java
The if keyword in Java programming language
The if keyword in Java programming language
In this tutorial,we will learn about The if keyword in Java programming language
In Java if keyword in java is used to if statement to test the boolean expression. It indicates conditional execution of a block. The condition must be evaluated to a boolean value.
An if statement may have an optional else clause containing code that is executed when the condition is false.
Syntax
Syntax of if keyword in java
if(boolean condition) { <statements> }
Syntax of if keyword with else keyword in java
if(boolean condition) { //It is executed when boolean condition is false <statements> } else // it is optional and executed when boolean condition is false { <statements> }
Example
class If_key{ public static void main(String args[]){ if(test_expression){ System.out.println("if condition is true this statements is executed"); } else{ System.out.println("if condition is false this statements is executed"); } } }
//else is a optional part in this program
Program
class If_Ex{ public static void main(String args[]){ int age=18; if(age<=19){ System.out.println("you are a teen age boy"); } else{ System.out.println("you are a person"); } } }
When the above code is compiled and executed, it will produce the following results
you are a teen age boy
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