QA Interview Handbook
  • ๐Ÿ Home Page
  • About Testing
    • ๐Ÿ’–Qualities of A Great Tester
  • Manual Testing
    • ๐Ÿ’กOverview
      • โœ‹Demand for Software Testing
      • ๐Ÿ˜„Tester's Role in Manual Testing
      • 7๏ธTesting Principles
      • ๐ŸšจV & V
      • โ”Interview Questions
    • โ™ป๏ธSDLC
      • ๐Ÿ“’Phase 1: Planning
      • ๐Ÿ”Phase 2: Requirement Analysis
      • ๐Ÿ‘”Phase 3: Design
      • โ›‘๏ธPhase 4: Development
      • ๐ŸงชPhase 5: Testing
      • ๐ŸššPhase 6: Deployment
      • ๐Ÿ–ฑ๏ธPhase 7: Maintenance
      • โš”๏ธCommon Challenges
      • โ”Interview Questions
    • ๐ŸŒ€STLC
    • ๐ŸŒŠWaterfall
    • โœณ๏ธAgile
      • ๐Ÿ˜Tester's Role in Scrum
    • ๐Ÿ”ขTypes
      • โฌœWhite Box Testing
      • โฌ›Black Box Testing
        • ๐Ÿ”ฐTechniques Used in Black Box Testing
        • ๐Ÿš˜Functional Testing
          • 1๏ธโƒฃUnit Testing
          • 2๏ธโƒฃIntegration Testing
            • ๐Ÿ”ฐTechniques Used in Integration Testing
          • 3๏ธโƒฃSystem Testing
            • ๐Ÿ“ผTypes of System Testing
            • ๐ŸŒŠPhases of System Testing
            • ๐ŸŒ€Regression Testing
            • ๐ŸŒซ๏ธSmoke Testing
          • 4๏ธโƒฃAcceptance Testing
            • โš™๏ธUser Acceptance Testing
            • ๐Ÿ…ฐ๏ธAlpha Testing
            • ๐Ÿ…ฑ๏ธBeta Testing
        • ๐Ÿ•ณ๏ธNon Functional Testing
      • ๐Ÿ“‘Grey Box Testing
    • ๐Ÿช„User Story
      • โบ๏ธSample User Stories
    • ๐Ÿ““Test Cases
      • โบ๏ธSample Test Cases
      • โ”Interview Questions
    • โœ–๏ธDefect Life Cycle
      • โ˜ฃ๏ธPriority + Severity
      • โบ๏ธSample Defect Reports
      • โ”Interview Questions
      • ๐Ÿ›Buggy Questions
    • ๐ŸŒAtlassian JIRA
      • ๐ŸžJIRA Issues
      • โ”Interview Questions
    • โ”Interview Questions
  • Accessibility Testing
    • ๐Ÿ’กOverview
    • ๐Ÿค“Tester's Role in Accessibility Testing
    • ๐Ÿ“šWCAG Principles
      • ๐Ÿ‘๏ธPerceivable
      • ๐ŸนOperable
      • ๐Ÿง Understandable
      • ๐Ÿค–Robust
    • ๐Ÿ”งAxe DevTools
      • โ”Interview Questions
    • ๐Ÿ““Test Cases
    • โ”Interview Questions
  • API Testing
    • ๐Ÿ’กOverview
    • ๐Ÿ˜€Tester's Role in API Testing
    • ๐ŸŠHTTP Methods & CRUD
      • ๐Ÿ‚HTTP Status Codes
    • ๐ŸAPI Tools
      • ๐ŸŸ Postman
        • โ˜„๏ธSending your first API request
        • ๐Ÿ”ฌHTTP Requests with Java
        • ๐ŸŽฒGitHub Sample
        • โ”Interview Questions
      • โ›‘๏ธREST Assured
        • ๐ŸŽ‡Dependency
        • โ”Interview Questions
    • ๐Ÿ““Test Cases
    • ๐ŸฆงAPI Cheatsheet
    • โ”Interview Questions
  • Database Testing
    • ๐Ÿ’กOverview
    • ๐Ÿ˜†Tester's Role in Database Testing
    • ๐Ÿ”ตSQL
      • โ›“๏ธConstraints
      • ๐Ÿ›ข๏ธReferencing a Column
      • ๐Ÿ”ผDDL Commands
      • ๐Ÿ”ผDML Commands
        • ๐Ÿ–Œ๏ธOperators
        • ๐Ÿ› ๏ธFunctions
          • โฏ๏ธAggregate Functions
        • ๐ŸŽ…Clauses
          • โซJoin Clauses
          • ๐Ÿ”ตFilter Clauses
          • โฌSet Operations
      • ๐ŸƒWildcard Character
      • โ”Interview Questions
    • ๐Ÿ““Test Cases
    • ๐ŸงคSQL Practice Sites
    • ๐ŸซSQL Cheatsheet
    • โ”Interview Questions
  • Java
    • โ›ฉ๏ธIntroduction
    • ๐Ÿ˜„Tester's Reason to Learn Java
    • โ“‚๏ธMain Method
      • โ”Interview Questions
    • ๐Ÿ“Variables & Types
      • ๐ŸชขSpecial Types
    • ๐ŸฅModifiers
    • ๐Ÿ…พ๏ธOperators
    • ๐ŸชกString
      • ๐ŸฉบString Methods
        • String Method Problems
      • ๐ŸšจDelimiter
      • โ”Interview Questions
    • ๐Ÿ–‡๏ธConditionals
      • ๐Ÿ’ŽCommon If Statements
      • ๐Ÿ’ŽCommon Ternary Operator Statements
    • โ“‚๏ธMath Class
    • ๐ŸŒŠLoops
      • ๐Ÿ’ŽCommon Loop Examples
      • ๐Ÿ”ƒNested For Loops
    • ๐ŸผOOPS
      • ๐Ÿ›๏ธClasses and Objects
        • โ”Interview Questions
      • ๐ŸŽƒConstructor
        • โšกStatic
          • โ”Interview Questions
        • ๐Ÿ“This() & Super()
          • โ”Interview Questions
        • ๐Ÿ€Finalization
      • ๐Ÿ”“Encapsulation
      • ๐ŸฅInheritance
      • ๐Ÿฆ‹Polymorphism
      • ๐Ÿ•ธ๏ธAbstraction
    • ๐ŸฎJava Practice Sites
    • โ˜‘๏ธData Structures + Algorithms
      • ๐Ÿ…พ๏ธBig O
      • โ˜‘๏ธData Structures
        • ๐Ÿ”ธArray
        • ๐Ÿ”ณArray Problems
        • Page
      • ๐ŸชŸSliding Window Technique
        • ๐ŸชŸSliding Window Problems
        • ๐ŸฅLeetCode #53
        • ๐ŸฅLeetCode #209
    • โ”Interview Questions
  • Automation Testing
    • ๐ŸšฐFlow
      • ๐Ÿ’กOverview
      • ๐ŸคฉTester's Role in Automation Testing
      • ๐Ÿ€Selenium
        • ๐Ÿ•ธ๏ธSelenium WebDriver
          • ๐Ÿ•ท๏ธWebDriver Commands
            • ๐ŸŒWebElement
              • ๐Ÿ”†HTML Tags
              • ๐Ÿ”ฌFind Element(s)
              • ๐ŸฆŽLocators
                • โŒXpath
                • ๐ŸฐCSS Selector
                • ๐Ÿ“€DOM
                • ๐Ÿ Quick Reference for XPath + CSS
            • โœ‹Waits
            • Browser Management
            • ๐ŸŽ๏ธNavigation
            • Alerts
          • ๐Ÿท๏ธAdvanced User Interactions
            • ๐Ÿ—ฏ๏ธAction vs. Actions
            • ๐Ÿ’งDrop Down
            • โœ…Check Box
            • ๐Ÿ–‡๏ธForms
          • โš ๏ธExceptions
        • ๐ŸOOPS + Selenium
        • ๐ŸšขFrameworks
          • โš“Module Based Framework
          • ๐ŸŽนKeyword Driven Framework
          • ๐ŸŽ‹Data Driven Framework
          • ๐ŸŒบHybrid Framework
          • ๐ŸŒดLog4j
          • ๐Ÿ“„Page Object Model
        • ๐ŸงชTesting Frameworks
          • ๐Ÿ’กTestNG
          • ๐Ÿ‰‘JUnit
          • ๐Ÿฅ’BDD
            • ๐Ÿฅ’Cucumber
        • ๐ŸŒ‰Selenium Grid
          • โœ–๏ธDesired Capabilities
        • โ”Interview Questions
      • ๐Ÿ”„API Testing with Selenium
      • โชDatabase Testing with Selenium
      • โ“‚๏ธMaven
      • ๐Ÿ™Git
        • โ”Interview Questions
      • ๐Ÿ•ต๏ธโ€โ™‚๏ธJenkins
        • โ”Interview Questions
      • ๐ŸณDocker
        • โ”Interview Questions
      • ๐Ÿ“™AWS
        • โ”Interview Questions
  • Behavioral
    • ๐Ÿ“ฃMixed Interview Questions
    • โญSTAR Method
      • ๐ŸŒŸSample Responses
Powered by GitBook
On this page
  • Check if a number is positive or negative:
  • Check if a number is even or odd:
  • Check if a number is between a range:
  • Check if a character is a vowel or consonant:
  • Check if a string is empty or not:
  • Check if an array is empty or not:
  • Check if a condition is true or false:
  • Check if a reference is null or not:
  • Check if two objects are equal or not:
  • Check if a condition is true, false, or unknown:
  • Check if a string contains a specific substring:
  • Check if a number is divisible by another number:
  • Check if a number is within a specific range:
  • Check if a character is uppercase or lowercase:
  • Check if an object is an instance of a specific class:
  • Check if an array contains a specific element:
  • Check if a file exists:
  • Check if a condition is false:
  • Check if a string starts or ends with a specific substring:
  • Check if a number is zero or non-zero:

Was this helpful?

  1. Java
  2. Conditionals

Common If Statements

Here's a list of common if statements that are often used in interviews:

Check if a number is positive or negative:

int number = 10;
if (number > 0) {
    // Code block for positive number
} else if (number < 0) {
    // Code block for negative number
} else {
    // Code block for zero
}

Check if a number is even or odd:

int number = 7;
if (number % 2 == 0) {
    // Code block for even number
} else {
    // Code block for odd number
}

Check if a number is between a range:

int number = 25;
if (number >= 10 && number <= 50) {
    // Code block for number within the range
} else {
    // Code block for number outside the range
}

Check if a character is a vowel or consonant:

char ch = 'a';
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') {
    // Code block for vowel
} else {
    // Code block for consonant
}

Check if a string is empty or not:

String str = "Hello";
if (str.isEmpty()) {
    // Code block for empty string
} else {
    // Code block for non-empty string
}

Check if an array is empty or not:

int[] numbers = {1, 2, 3};
if (numbers.length == 0) {
    // Code block for empty array
} else {
    // Code block for non-empty array
}

Check if a condition is true or false:

boolean flag = true;
if (flag) {
    // Code block if flag is true
} else {
    // Code block if flag is false
}

Check if a reference is null or not:

String str = null;
if (str == null) {
    // Code block if str is null
} else {
    // Code block if str is not null
}

Check if two objects are equal or not:

String str1 = "Hello";
String str2 = "World";
if (str1.equals(str2)) {
    // Code block if str1 equals str2
} else {
    // Code block if str1 does not equal str2
}

Check if a condition is true, false, or unknown:

boolean condition = true;
if (condition) {
    // Code block if condition is true
} else if (!condition) {
    // Code block if condition is false
} else {
    // Code block if condition is unknown
}

Check if a string contains a specific substring:

String str = "Hello, World!";
if (str.contains("World")) {
    // Code block if str contains "World"
} else {
    // Code block if str does not contain "World"
}

Check if a number is divisible by another number:

int number = 15;
int divisor = 3;
if (number % divisor == 0) {
    // Code block if number is divisible by divisor
} else {
    // Code block if number is not divisible by divisor
}

Check if a number is within a specific range:

int number = 20;
int lowerBound = 10;
int upperBound = 30;
if (number >= lowerBound && number <= upperBound) {
    // Code block if number is within the range
} else {
    // Code block if number is outside the range
}

Check if a character is uppercase or lowercase:

char ch = 'A';
if (Character.isUpperCase(ch)) {
    // Code block if ch is uppercase
} else if (Character.isLowerCase(ch)) {
    // Code block if ch is lowercase
} else {
    // Code block if ch is not a letter
}

Check if an object is an instance of a specific class:

Object obj = "Hello";
if (obj instanceof String) {
    // Code block if obj is an instance of String
} else {
    // Code block if obj is not an instance of String
}

Check if an array contains a specific element:

int[] numbers = {1, 2, 3, 4, 5};
int target = 3;
boolean found = false;
for (int num : numbers) {
    if (num == target) {
        found = true;
        break;
    }
}
if (found) {
    // Code block if target is found in the array
} else {
    // Code block if target is not found in the array
}

Check if a file exists:

import java.io.File;

File file = new File("path/to/file.txt");
if (file.exists()) {
    // Code block if file exists
} else {
    // Code block if file does not exist
}

Check if a condition is false:

boolean condition = false;
if (!condition) {
    // Code block if condition is false
} else {
    // Code block if condition is true
}

Check if a string starts or ends with a specific substring:

String str = "Hello, World!";
if (str.startsWith("Hello")) {
    // Code block if str starts with "Hello"
} else if (str.endsWith("World!")) {
    // Code block if str ends with "World!"
} else {
    // Code block if str does not start with "Hello" and does not end with "World!"
}

Check if a number is zero or non-zero:

int number = 0;
if (number == 0) {
    // Code block if number is zero
} else {
    // Code block if number is non-zero
}
PreviousConditionalsNextCommon Ternary Operator Statements

Last updated 1 year ago

Was this helpful?

๐Ÿ–‡๏ธ
๐Ÿ’Ž