Book Image

Hands-On Automation Testing with Java for Beginners

Book Image

Hands-On Automation Testing with Java for Beginners

Overview of this book

Java is one of the most commonly-used software languages by programmers and developers. Are you from a non-technical background and looking to master Java for your automation needs? Then Hands-On Automation Testing with Java for Beginners is for you. This book provides you with efficient techniques to effectively handle Java-related automation projects. You will learn how to handle strings and their functions in Java. As you make your way through the book, you will get to grips with classes and objects, along with their uses. In the concluding chapters, you will learn about the importance of inheritance and exceptions with practical examples. By the end of this book, you will have gained comprehensive knowledge of Java.
Table of Contents (17 chapters)
Title Page
Copyright and Credits
Packt Upsell
Contributors
Preface
Index

if...else condition


Before we learn the while and do...while loops, we will discuss the if condition in this section. In a Java program, when the if conditional statement is used, the statement in the if block is executed only if the condition is satisfied. Otherwise the statement from else block is run. Also this execution is just takes place once. In a for loop, a variable is initiated and the loop runs till the condition is satisfied.

However, in the if case, it will not keep on looping. It will just go inside the loop once the if condition is satisfied; otherwise, it will go into the else block. So, control will execute the statements present in this else block, as shown in the following screenshot: 

Output of the if...else condition as per the code

But all this happens only once, unlike the for loop, where a condition is satisfied until it goes back and executes.

Let's take a look at the following example:

    if(5>2)
    {
        System.out.println("success");
    }
    else
    {
...