A String's value cannot change after creation; methods like concat or replace return new objects. Immutability enables the string pool, safe sharing across threads, cached hash codes for HashMap keys, and security. Use StringBuilder when building strings in a loop to avoid creating many intermediate objects.
Full answer with examplesInterview questions / Languages
Java Interview Questions
Java remains the most common language for Selenium and REST Assured frameworks. Expect OOP, collections, exceptions and a short coding exercise.
6 questions · 2 beginner· 3 intermediate· 1 advanced
beginner questions
An abstract class can hold state, constructors and implemented methods, and a class extends only one. An interface defines a contract with no instance state; since Java 8 it can have default and static methods, and a class can implement many. WebDriver is an interface; BasePage is often abstract.
Full answer with examplesintermediate questions
Explain the equals() and hashCode() contract. What breaks if you violate it?
intermediate 2–5 yrs
If two objects are equal by equals(), they must return the same hashCode(); unequal objects may share a hash. Hash-based collections find the bucket by hashCode and then compare with equals, so overriding only equals makes HashSet and HashMap lookups fail. Records and Objects.hash make correct implementations easy.
Full answer with examplesChecked vs unchecked exceptions: how should a test framework handle exceptions?
intermediate 2–5 yrs
Checked exceptions extend Exception and must be caught or declared; unchecked ones extend RuntimeException. In a framework, let unexpected exceptions fail the test, wrap low-level checked exceptions in meaningful unchecked ones with the cause kept, use try-with-resources, and never swallow exceptions.
Full answer with examplesUsing Java streams, find the duplicate values in a list and count their occurrences.
intermediate 2–5 yrs
Group with Collectors.groupingBy(Function.identity(), Collectors.counting()) and keep entries with a count above one. For just the duplicate values, add to a HashSet and collect elements whose add returns false. Explain complexity, ordering (LinkedHashMap) and when a plain loop is clearer.
Full answer with examplesadvanced questions
Never share a WebDriver between threads. Give each thread its own driver via ThreadLocal or injection scoped per test, avoid static mutable state, and isolate test data. ThreadLocal stores a separate value per thread, but you must call remove() in teardown because thread pools reuse threads.
Full answer with examples