Java if statement Last Updated : 14 Oct, 2025 Comments Improve Suggest changes 71 Likes Like Report In Java, an if statement is the simplest decision-making statement. It is used to execute a block of code only if a specific condition is true. If the condition is false, the code inside the if block is skipped.The condition must evaluate to a Boolean value (true or false).If curly braces {} are omitted, only the immediately next statement is considered part of the if block.Syntax:if (condition) { // Statements executed if the condition is true}Example: with Curly Braces Java class GfG{ public static void main(String args[]){ int i = 10; // using if statement if (i < 15){ System.out.println("10 is less than 15"); } System.out.println("Outside if-block"); // both statements will be printed } } Output10 is less than 15 Outside if-block Explanation:The condition i < 15 evaluates to true, so the message inside the if block is printed.The second System.out.println() executes regardless of the condition.Example: without Curly Braces Java class GFG { public static void main(String args[]){ int i = 5; // if statement without braces if (i > 0) System.out.println("i is positive"); System.out.println( "This statement runs regardless of if condition"); } } Outputi is positive This statement runs regardless of if condition Explanation:Only the first statement after if is executed when the condition is true.The second System.out.println() is not part of the if block, so it executes in all cases.Working of if statementControl reaches the if statement.The condition is evaluated.If the condition is true, the body inside the if block executes.If the condition is false, the program skips the if block.Flow continues with the statements after the if block.Flowchart if statement: Create Quiz Comment C chinmoy lenka Follow 71 Improve C chinmoy lenka Follow 71 Improve Article Tags : Java java-basics Explore Java BasicsIntroduction to Java3 min readJava Programming Basics9 min readJava Methods6 min readAccess Modifiers in Java4 min readArrays in Java7 min readJava Strings7 min readRegular Expressions in Java3 min readOOP & InterfacesClasses and Objects in Java5 min readAccess Modifiers in Java4 min readJava Constructors4 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages2 min readJava Interface7 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java4 min readIterator in Java4 min readJava Comparator Interface5 min readException HandlingJava Exception Handling6 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java7 min readFile Handling in Java4 min readJava Method References7 min readJava 8 Stream Tutorial7 min readJava Networking6 min readJDBC Tutorial5 min readJava Memory Management3 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers1 min readJava Programs - Java Programming Examples7 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz1 min readJava Project Ideas For Beginners and Advanced15+ min read Like