SoftwareTestPilot
8 Q&A · 1 Year Experience

Java for Testers Interview Questions for 1 Year Experience (2026)

Core Java 17 & Collections interview questions for Junior Java Automation Testers with 1 year of experience.

  • 3 min read
  • Difficulty: Easy
  • 1 yr · Junior Java Automation
  • Updated October 2026
  • SoftwareTestPilot
SoftwareTestPilot
QA Editorial Team
Published:
0 / 8 reviewed
0%

1. Java Language Basics Testers Use Daily

Easy Very Common 1 minQ1 / 8

Q1.What is the difference between == and equals() when comparing Strings?

Detailed explanation

Short answer: == checks whether two references point to the same object; equals() checks whether the text is the same. In tests, always compare expected and actual text with equals() (or an assertion library, which calls it for you).

String a = "Login";
String b = new String("Login");
System.out.println(a == b);       // false - two different objects
System.out.println(a.equals(b));  // true  - same characters

Common failure: driver.getTitle() == "Dashboard" fails even when the title looks right, because the browser returns a new String object.

Common mistakes
  • Using == for text from the browser or an API response
  • Calling equals() on a value that may be null - write "Expected".equals(actual) or use Objects.equals
Follow-up questions
  • What does equalsIgnoreCase do?
  • Why do string literals sometimes pass an == check?
RelatedQ3
Easy Very Common 1 minQ2 / 8

Q2.Checked vs unchecked exceptions: which ones will you meet in test code?

Detailed explanation

Short answer: checked exceptions (such as IOException) must be caught or declared with throws; unchecked exceptions extend RuntimeException and are not forced by the compiler. Selenium's NoSuchElementException and TimeoutException are unchecked.

When you read a test-data file, use try-with-resources so the file is always closed:

try (BufferedReader reader = Files.newBufferedReader(Path.of("users.csv"))) {
    String header = reader.readLine();
    System.out.println(header);
} // reader.close() runs automatically, even if readLine throws

Common failure: wrapping a whole test in catch (Exception e) {}. The test then passes when it should fail.

Common mistakes
  • Swallowing exceptions in tests
  • Catching Exception instead of the specific type
Follow-up questions
  • What is the difference between throw and throws?
  • When would you create your own exception class?
Easy Very Common 1 minQ3 / 8

Q3.What does static mean, and why is a static WebDriver a problem?

Detailed explanation

Short answer: a static field belongs to the class, so every object (and every thread) shares one copy. A static WebDriver works when tests run one at a time, but once tests run in parallel, two tests drive the same browser and fail randomly.

public class BaseTest {
    protected WebDriver driver;          // one per test instance

    @BeforeMethod
    public void setUp() { driver = new ChromeDriver(); }

    @AfterMethod
    public void tearDown() { driver.quit(); }
}

Static is fine for constants (static final String BASE_URL) and small helper methods that keep no state.

Common mistakes
  • Making driver static to 'share' it between page classes - pass it through the constructor instead
Follow-up questions
  • How does ThreadLocal help with parallel tests? (covered on the 4-year page)
Easy Common 1 minQ4 / 8

Q4.How do access modifiers support the Page Object Model?

Detailed explanation

Short answer: keep locators private and expose public actions. Tests then say what the user does, and a locator change touches one class only.

public class LoginPage {
    private final WebDriver driver;
    private final By email = By.id("email");
    private final By password = By.id("password");
    private final By submit = By.cssSelector("button[type='submit']");

    public LoginPage(WebDriver driver) { this.driver = driver; }

    public void loginAs(String user, String pass) {
        driver.findElement(email).sendKeys(user);
        driver.findElement(password).sendKeys(pass);
        driver.findElement(submit).click();
    }
}

The four levels are private (class only), package-private (no keyword), protected (package and subclasses) and public.

Follow-up questions
  • Should page objects contain assertions?
Confidence check

If you can confidently answer the Java Language Basics Testers Use Daily questions above, you're well prepared for this section of your interview. Move on, or rehearse the trickier ones aloud with our AI mock interviewer.

2. Collections and Short Coding Questions

Easy Common 1 minQ5 / 8

Q5.When would you use ArrayList, HashSet or HashMap in a test?

Detailed explanation

Short answer: use a List when order matters or duplicates are allowed (rows in a table), a Set when you need unique values (checking a dropdown has no duplicate options), and a Map for key-value data (column name to cell value).

List<String> options = List.of("India", "Japan", "India");
Set<String> unique = new HashSet<>(options);
System.out.println(options.size() == unique.size()); // false - a duplicate exists

Note that HashSet and HashMap do not keep insertion order. Use LinkedHashSet/LinkedHashMap when the order must match what the page shows.

Common mistakes
  • Asserting the order of items read from a HashSet
Follow-up questions
  • What is the difference between List.of and new ArrayList<>()? (List.of is unmodifiable)
Medium Occasional 1 minQ6 / 8

Q6.Why does removing items inside a for-each loop throw ConcurrentModificationException?

Detailed explanation

Short answer: the for-each loop uses an iterator, and changing the list directly while iterating makes the iterator fail fast. Use removeIf or the iterator's own remove().

List<String> names = new ArrayList<>(List.of("a", "", "b", ""));

// for (String n : names) if (n.isEmpty()) names.remove(n);  // throws ConcurrentModificationException

names.removeIf(String::isEmpty);
System.out.println(names); // [a, b]
Follow-up questions
  • Would the same code fail on List.of(...)? (yes, with UnsupportedOperationException, because it cannot be changed at all)
Easy Occasional 1 minQ7 / 8

Q7.Coding: count how many times each character appears in a string.

Detailed explanation

This is a common screening question for junior automation roles. Explain the idea first: walk through the characters and keep a count in a map.

import java.util.LinkedHashMap;
import java.util.Map;

public class CharCount {
    public static void main(String[] args) {
        String input = "testing";
        Map<Character, Integer> counts = new LinkedHashMap<>();
        for (char ch : input.toCharArray()) {
            counts.merge(ch, 1, Integer::sum);
        }
        System.out.println(counts); // {t=2, e=1, s=1, i=1, n=1, g=1}
    }
}

Mention the edge cases you would test: empty string, upper vs lower case, and spaces.

Follow-up questions
  • How would you find the first non-repeating character?
Easy Occasional 1 minQ8 / 8

Q8.Why are Strings immutable, and when should you use StringBuilder?

Detailed explanation

Short answer: a String cannot change after it is created; every + makes a new object. Inside a loop that builds a long text (for example a CSV report), use StringBuilder.

StringBuilder report = new StringBuilder("test,status\n");
for (String test : List.of("login", "search")) {
    report.append(test).append(",PASS\n");
}
System.out.print(report);

Expected output: three lines - the header, then login,PASS and search,PASS.

Follow-up questions
  • Is StringBuilder thread-safe? (No - StringBuffer is, but it is rarely needed)
RelatedQ6
Confidence check

If you can confidently answer the Collections and Short Coding Questions questions above, you're well prepared for this section of your interview. Move on, or rehearse the trickier ones aloud with our AI mock interviewer.

Quick revision

  1. Q1: What is the difference between == and equals() when comparing Strings — Short answer: == checks whether two references point to the same object; equals() checks whether the text is the same.
  2. Q2: Checked vs unchecked exceptions: which ones will you meet in test code — Short answer: checked exceptions (such as IOException ) must be caught or declared with throws ; unchecked exceptions extend RuntimeException and are not forced by the compiler.
  3. Q3: What does static mean, and why is a static WebDriver a problem — Short answer: a static field belongs to the class, so every object (and every thread) shares one copy.
  4. Q4: How do access modifiers support the Page Object Model — Short answer: keep locators private and expose public actions.
  5. Q5: When would you use ArrayList, HashSet or HashMap in a test — Short answer: use a List when order matters or duplicates are allowed (rows in a table), a Set when you need unique values (checking a dropdown has no duplicate options), and a Map

Frequently asked questions

1.How much Java do I need with 1 year of automation experience?
Interviewers usually expect clean basics: Strings, collections, exceptions, OOP (classes, inheritance, interfaces) and small coding problems. Streams and concurrency are normally asked at the 3-5 year level.
2.How is this page different from the 4-year Java page?
This page covers language basics and simple coding. The 4-year page covers streams, parallel execution with ThreadLocal, concurrency and framework design decisions.

Java jobs hiring now

Live, indexable Java openings — updated daily in Jobs Radar.

Browse all QA jobs on Jobs Radar

Loading current openings…

Home