Java SDET Interview Questions with Sample Answers
Q: What are OOPs concepts in Java?
A: Java supports four OOPs principles – Encapsulation, Inheritance, Polymorphism,
Abstraction.
Q: Difference between interface and abstract class?
A: An interface provides a contract with only method declarations (Java 7), while an
abstract class can have both abstract and concrete methods.
Q: What is the difference between == and equals()?
A: == compares references; equals() compares object content.
Q: Access modifiers in Java?
A: private (within class), default (within package), protected (package + subclass), public
(everywhere).
Q: Method overloading vs overriding?
A: Overloading: same method name, different params. Overriding: child class redefines
parent method.
Q: ArrayList vs LinkedList?
A: ArrayList is faster for search; LinkedList is better for insert/delete.
Q: HashMap vs Hashtable?
A: HashMap is non-synchronized and allows one null key; Hashtable is synchronized and
doesn't allow null keys.
Q: How does HashMap work internally?
A: It uses hashCode() to find a bucket and equals() to resolve collisions.
Q: Checked vs Unchecked exceptions?
A: Checked: compile-time (e.g., IOException). Unchecked: runtime (e.g.,
NullPointerException).
Q: throw vs throws?
A: throw: actually throws exception. throws: declares possible exceptions in method
signature.
Q: How do you launch a browser in Selenium?
A: WebDriver driver = new ChromeDriver(); System.setProperty is used for setting driver
path.
Q: findElement vs findElements?
A: findElement returns first match, throws exception if not found. findElements returns list,
can be empty.
Q: Types of waits in Selenium?
A: Implicit (global), Explicit (condition-based), Fluent (custom polling intervals).
Q: How do you handle alerts and frames?
A: Use driver.switchTo().alert() for alerts and driver.switchTo().frame() for frames.
Q: How do you handle multiple windows?
A: Use driver.getWindowHandles() and driver.switchTo().window(handle).
Q: Why use TestNG?
A: It supports annotations, groups, priorities, parameterization, and generates reports.
Q: What is DataProvider in TestNG?
A: Used for data-driven testing; supplies test data to test methods.
Q: What is BDD?
A: Behavior Driven Development allows writing test scenarios in plain English (Gherkin
syntax).
Q: What are Given, When, Then?
A: Given - precondition, When - action, Then - verification.
Q: How do you link Cucumber with Selenium?
A: Step definitions written in Java use Selenium commands. Runner class uses TestNG or
JUnit.
Q: How do you send a GET request in RestAssured?
A: given().when().get(url).then().statusCode(200);
Q: How do you pass headers or parameters?
A: Use .header(), .queryParam(), or .pathParam().
Q: How do you validate the JSON response?
A: Use .body() for assertions or map response to POJO using Jackson/Gson.
Q: What is a framework? How is your framework structured?
A: POM-based with base, utilities, test data, test classes, and page classes.
Q: How do you handle test data?
A: Stored in JSON/Excel/.properties; read using Jackson or Apache POI.
Q: How do you generate reports and logs?
A: ExtentReports for reports, Log4j or SLF4J for logging.
Q: How do you run tests using Jenkins?
A: Git + Maven + Jenkins. Use Maven command like mvn clean test in job config.
Q: What are Lambda expressions?
A: Short syntax for functional interfaces: (a, b) -> a + b
Q: What is a Stream in Java 8?
A: Functional-style operations on collections: filter, map, reduce, collect.