- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the ‘if’ statement in Java and how to use it?
An if statement consists of a Boolean expression followed by one or more statements.
Syntax
Following is the syntax of an if statement −
if(Boolean_expression) { // Statements will execute if the Boolean expression is true }
If the Boolean expression evaluates to true, then the block of code inside the if statement will be executed. If not, the first set of code after the end of the if statement (after the closing curly brace) will be executed.
Example
public class Test { public static void main(String args[]) { int x = 10; if( x < 20 ) { System.out.print("This is if statement"); } } }
Output
This is if statement.
- Related Articles
- What is the ‘if else’ statement in Java and how to use it?
- What is the ‘nested if’ statement in Java and how to use it?
- What is the ‘if...else if...else’ statement in Java and how to use it?
- What is a break statement in Java and how to use it?
- What is a continue statement in Java and how to use it?
- What is a switch case statement in Java and how to use it?
- What is #if DEBUG and How to use it in C#?
- What is method hiding in Java and how to use it?
- What is the type conversion operator ( ) in Java and how to use it?
- How to use nested if statement in Python?
- What is SignalR and how to use it?
- How to use IF statement in MySQL using Python?
- How to use ‘else if ladder’ conditional statement is C language?
- What is the FlatList component and how to use it in React Native?
- What is the SectionList component and how to use it in React Native?

Advertisements