1. Variables and Data Types in Java

Understanding Variables and Types in Java

Java is statically typed: you must declare the variable's type before using it.

In test automation, you will constantly handle:
- int / double: Status codes, timeout seconds, element counts.
- String: URLs, page titles, usernames, CSS/XPath locators.
- boolean: Element states like isDisplayed(), isEnabled(), and isSelected().

public class VariablesDemo {
    public static void main(String[] args) {
        String baseUrl = "https://targetqa.com";
        int defaultTimeout = 30;
        boolean isHeadless = true;
        
        System.out.println("Target: " + baseUrl);
        System.out.println("Timeout: " + defaultTimeout + "s");
    }
}

Task

  • Complete the code:
  • Declare a `String` variable named `targetUrl` with value `"https://targetqa.com"`.
  • Declare an `int` variable named `defaultTimeout` with value `30`.
  • Print both variables using `System.out.println()`.
💡Common doubts
Did you like the problem?
Lesson 1 of 18
Java
Loading code editor…
Next