Use it for
Revision before coding, TestNG work, Selenium helpers, and interview practice.
A focused Java quick reference for automation engineers covering the core language concepts we teach before Selenium.
Revision before coding, TestNG work, Selenium helpers, and interview practice.
Language basics that show up constantly in framework code and live coding rounds.
Prefer readable methods, clear naming, and small reusable objects instead of long procedural test code.
Use this with the Selenium, TestNG, and framework cheat sheets.
Java is strongly typed, so declare the type explicitly and keep values predictable.
int score = 95; double duration = 2.5; boolean passed = true; String course = "Selenium"; char grade = 'A';
Use conditionals to branch logic clearly in utility code or validation helpers.
if (score >= 90) {
System.out.println("Excellent");
} else if (score >= 50) {
System.out.println("Pass");
} else {
System.out.println("Fail");
}
Loops are useful for lists, tables, and reusable data-driven checks.
for (int i = 0; i < 3; i++) {
System.out.println(i);
}
for (String topic : List.of("Java", "Selenium", "TestNG")) {
System.out.println(topic);
}
Methods keep repeated test logic and framework utilities maintainable.
public static int addPoints(int current, int extra) {
return current + extra;
}
public static void logMessage(String message) {
System.out.println(message);
}
String operations are common in assertions, locators, logs, and test data shaping.
String name = "Playwright";
System.out.println(name.length());
System.out.println(name.toUpperCase());
System.out.println(name.contains("wright"));
System.out.println(name.equals("Playwright"));
Framework design depends on understanding how objects hold state and behavior.
class Student {
String name;
Student(String name) {
this.name = name;
}
void greet() {
System.out.println("Hello " + name);
}
}
Inheritance, abstraction, and interfaces matter when building page classes and base utilities.
interface Reportable {
void generate();
}
abstract class BasePage {
abstract void open();
}
Catch only when you can add context or recover meaningfully.
try {
int result = 10 / 2;
System.out.println(result);
} catch (Exception e) {
System.out.println("Something failed: " + e.getMessage());
} finally {
System.out.println("Cleanup done");
}
Lists, sets, and maps appear in test data, configuration, and result aggregation.
Listtools = new ArrayList<>(); tools.add("Selenium"); tools.add("TestNG"); Map scores = new HashMap<>(); scores.put("Pramod", 95);