Cheat sheets / Java for SDETs

Java for SDETs

The Java you are asked to write and explain in automation interviews.

OOP in a framework

Encapsulation
Page objects hide locators behind methods.
Inheritance vs composition
Keep base classes thin; pass helpers in rather than extending deep chains.
Abstract class vs interface
Shared state and partial code vs a pure contract; a class can implement many interfaces.

Collections

List / Set / Map
Ordered with duplicates; unique; key-value.
HashMap vs TreeMap vs LinkedHashMap
Fast and unordered; sorted by key; insertion order.
equals and hashCode
Override both together or HashMap and HashSet misbehave.

Common coding tasks

Reverse a string
StringBuilder.reverse(), or a loop from the end.
new StringBuilder(s).reverse().toString()
Count characters
Map<Character,Integer> with merge.
map.merge(c, 1, Integer::sum);
Find duplicates
Add to a Set; if add returns false it is a duplicate.

Exceptions and strings

Checked vs unchecked
Checked must be handled or declared; unchecked are runtime errors.
String vs StringBuilder
Strings are immutable; use StringBuilder for repeated edits.
== vs equals
Reference comparison vs value comparison.