Share on Google+Share on Google+

The if Keyword

The if is a keyword, which is used to perform the selection statement.

The if Keyword  


The if is a keyword, which is used to perform the selection statement. It is used to execute the statements after evaluating the condition specified in it as true. When the condition is true, the code in the "if" block is executed. When false, the code in the if block is skipped. It starts a branching statement.

It is used to define a statement or block of statements that are executed in case, the test condition specified by the if keyword evaluates to true. When the if condition evaluates to true, the code after the if block is executed.

The if is a java keyword that may not be used as identifiers i.e. you cannot declare a variable or class with this name in your Java program. If an optional block is defined with the else keyword, then the else block is executed when the test evaluates to false.

The following shows the format of the if selection Construct syntax. 

if (<condition>){




if (condition){






 Here is an example of if keyword: 

class IfDemo{
  public static void main(String[] args){


   if (x > 1)
   System.out.println("Greater than 1");
  if (x < 1)
   System.out.println("Less than 1");




In the above example if we declare int x = 1, the statements will show some of the valid boolean expressions to the if statement.



Posted on: November 11, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: The if Keyword  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image