PURPOSE: Solid foundation in Java concepts every QA automation engineer must know to write reliable, maintainable automation code.
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}classkeyword defines a classmainmethod is the program entry point- Statements end with a semicolon
;
public class User {
private String name;
private int age;
public User(String name, int age) {
this.name = name;
this.age = age;
}
public void greet() {
System.out.println("Hello, " + name);
}
}
User user = new User("Ahmed", 30);
user.greet();class Animal {
void sound() {
System.out.println("Some sound");
}
}
class Dog extends Animal {
@Override
void sound() {
System.out.println("Bark");
}
}- Method overloading (same method name, different parameters)
- Method overriding (subclass changes behavior of superclass method)
- Use
privatefields with public getters/setters - Controls access and improves maintainability
try {
int a = 10 / 0;
} catch (ArithmeticException e) {
System.out.println("Cannot divide by zero");
} finally {
System.out.println("This always runs");
}- Checked exceptions (require explicit handling)
- Unchecked exceptions (runtime exceptions)
- Use specific catch blocks for better debugging
List<String> names = new ArrayList<>();
names.add("Ahmed");
names.add("John");
System.out.println(names.get(0)); // AhmedSet<String> uniqueNames = new HashSet<>();
uniqueNames.add("Ahmed");
uniqueNames.add("Ahmed"); // duplicate ignoredMap<String, Integer> ages = new HashMap<>();
ages.put("Ahmed", 30);
ages.put("John", 25);
System.out.println(ages.get("Ahmed")); // 30List<String> names = Arrays.asList("Ahmed", "John", "Sara");
names.stream()
.filter(name -> name.startsWith("A"))
.forEach(System.out::println); // Ahmed- Stream API enables functional-style operations on collections
- Common operations: filter, map, reduce, collect
Thread thread = new Thread(() -> System.out.println("Running in separate thread"));
thread.start();- Use
synchronizedto control access to shared resources - Use thread pools (
ExecutorService) to manage multiple threads
Stringmethods:contains(),split(),replace(),trim(),equalsIgnoreCase()Mathclass:Math.max(),Math.min(),Math.random()- Date and time API (
java.timepackage):LocalDate,LocalDateTime - Wrapper classes:
Integer.parseInt(),Boolean.parseBoolean()
- Follow Java naming conventions (camelCase for methods/variables, PascalCase for classes)
- Keep code modular and reusable
- Avoid hardcoding test data — use constants or external files
- Handle exceptions gracefully and log useful info
- Use comments sparingly but clearly
- Write unit tests for utility methods
- Learn to debug using IDE features (breakpoints, step execution)
Master these Java basics to build strong automation frameworks and solve real-world test challenges efficiently.