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.

Usage of If key word

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

try keyword in Java

Catch keyword in Java

implements keyword in java

public Key words in Java

static keyword in Java language

Volatile Keyword in Java

Transient keyword in Java

Package keyword in Java

class keyword in Java

boolean keyword in Java

break keyword in Java

do keyword in Java

double keyword in Java

This keyword in Java

final keyword in Java

switch keyword in Java

interface keyword in java

extends keyword in Java language

 

Suggested for you

 Java language Keywords

C language Keywords

 Python language Keywords

keywords in C language

Usage of final keyword in Java

Usage of this keyword in Java

Finally keyword in Java language

If statement in Java

If statement in C

If statement in C++

If statement in Python

Nested if statement in Java

 

 

 

 

The do keyword in Java programming language
The else keyword in Java programming language
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

6 months ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

6 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

6 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

9 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

1 year ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

1 year ago