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 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> }
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
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…