Core Java Notes for Selenium Automation Tester
Collections
- List, Set, Map covered in detail. - ArrayList capacity handling (default 10, grows by 50%). -
HashSet vs TreeSet differences explained. - Map methods: put, get, entrySet, keySet, values, etc.
Exception Handling
- Checked vs Unchecked exceptions explained. - try-catch-finally usage. - Custom exceptions
possible using 'extends Exception'. - StaleElementReferenceException in Selenium handled with
WebDriverWait and re-locating element.
Multithreading
- Thread creation using 'Thread' class and 'Runnable' interface. - Synchronization basics. -
Executor framework introduced in Java 5 for concurrency.
File Handling
- File class used for creating and checking file properties. - Reading file using FileReader +
BufferedReader. - Writing file using FileWriter. - Properties file important for config in Selenium
frameworks.
Java 8 Features
- Lambda expressions: concise representation of functional interface implementations. - Functional
Interfaces: @FunctionalInterface with exactly one abstract method. - Streams API: filter, map,
forEach, collect, count. - Default & Static methods in interfaces. - Method references and Optional
class basics. - New Date & Time API introduced.
OOP Concepts
- Encapsulation: private fields + getters/setters (used in POM). - Inheritance: reusability (BaseTest,
LoginTest examples). - Polymorphism: overloading and overriding, runtime polymorphism with
WebDriver driver = new ChromeDriver(). - Abstraction: achieved using abstract classes or
interfaces (WebDriver interface).
Java Memory Management
- Stack stores method calls, Heap stores objects. - Garbage Collector automatically frees
unreferenced objects. - final: constant variable. - finally: block always executed. - finalize(): method
called before object destruction (not reliable).
Immutable Classes
- Example: String class. - Custom immutable class created with final variables and no setters. -
Provides thread-safety and reliability.
Wrapper Classes & Autoboxing
- Wrappers convert primitives into objects (int -> Integer). - Autoboxing: automatic conversion
primitive -> wrapper. - Unboxing: wrapper -> primitive. - Used in Collections as they store objects
only.
Static vs Non-Static
- Static variables/methods belong to class, not instance. - Useful in utilities and counters. -
Non-static requires object creation.
Inner Classes
- Normal inner class. - Static nested class. - Anonymous class (replaced by lambdas in Java 8).