Introduction: Why Java Is Needed for Automation Testing
Java is the backbone of automation testing in most service-based companies, including Test Yantra. The majority of automation frameworks—Selenium WebDriver, TestNG, JUnit, Cucumber, REST Assured—are heavily Java-oriented.
Test Yantra interviews focus on:
- Core Java fundamentals
- Automation concepts
- Real-time framework usage
- Problem-solving ability
If you understand Java well, automation becomes logical instead of memorised.
Core Java Topics for Testing
1. OOP Concepts
- Inheritance
- Polymorphism
- Abstraction
- Encapsulation
2. Collections Framework
- List, Set, Map
- ArrayList vs LinkedList
- HashMap vs Hashtable
3. Multithreading
- Thread class
- Runnable interface
- Synchronization
4. Exception Handling
- try–catch
- throws vs throw
- Custom exceptions
5. Java 8 Features
- Streams
- Lambda expressions
- Functional interfaces
Test Yantra Java Interview Questions and Answers (Core + Automation)
1. What is Java?
Java is a platform-independent, object-oriented programming language used extensively in automation testing.
2. Why is Java preferred in Selenium automation?
- Strong OOP support
- Large community
- Easy integration with TestNG, Maven, Jenkins
- Platform independence
3. Difference between JDK, JRE, and JVM?
| Term | Description |
| JVM | Executes bytecode |
| JRE | JVM + libraries |
| JDK | JRE + compiler |
4. What is OOP and why is it important in automation?
OOP helps in framework design, reusability, and maintainability.
5. Explain Encapsulation with example.
class Login {
private String password;
public void setPassword(String pwd) {
password = pwd;
}
public String getPassword() {
return password;
}
}
Expected Output:
Data is accessed securely using getters and setters.
6. What is inheritance?
Acquiring properties of a parent class.
class Browser {
void open() {
System.out.println(“Browser opened”);
}
}
class Chrome extends Browser {
void launch() {
System.out.println(“Chrome launched”);
}
}
Output:
Browser opened
Chrome launched
7. What is polymorphism?
Same method name, different behaviour.
8. Difference between overloading and overriding?
| Overloading | Overriding |
| Compile time | Runtime |
| Same class | Parent-child |
9. What is an interface?
A blueprint that supports multiple inheritance.
10. Why collections are important in automation?
To store:
- WebElements
- Test data
- API responses
11. Difference between List and Set?
- List allows duplicates
- Set does not allow duplicates
12. ArrayList vs LinkedList?
| ArrayList | LinkedList |
| Faster retrieval | Faster insertion |
| Uses array | Uses nodes |
13. What is HashMap?
Stores data as key-value pairs.
14. How to iterate HashMap?
HashMap<String, Integer> map = new HashMap<>();
map.put(“Age”, 25);
for(Map.Entry<String, Integer> entry : map.entrySet()){
System.out.println(entry.getKey() + ” ” + entry.getValue());
}
15. What is exception?
An unwanted event that disrupts program flow.
16. Checked vs Unchecked exception?
| Checked | Unchecked |
| Compile time | Runtime |
| IOException | NullPointerException |
17. try vs throws?
- try handles exception
- throws declares exception
18. What is multithreading?
Executing multiple threads simultaneously.
19. Why multithreading in automation?
Parallel execution of test cases.
20. Java 8 Stream example:
List<Integer> list = Arrays.asList(1,2,3,4);
list.stream().filter(i -> i%2==0).forEach(System.out::println);
Output:
2
4
Selenium WebDriver Java Coding Questions
21. How to launch browser in Selenium?
WebDriver driver = new ChromeDriver();
driver.get(“https://example.com”);
22. Different locators in Selenium?
- id
- name
- className
- xpath
- cssSelector
23. Absolute vs Relative XPath?
| Absolute | Relative |
| Starts with / | Starts with // |
| Slow | Fast |
24. XPath for dynamic element?
//input[contains(@id,’email’)]
25. What are waits in Selenium?
- Implicit wait
- Explicit wait
- Fluent wait
26. Explicit wait example:
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(“login”)));
27. Difference between Thread.sleep and wait?
| Thread.sleep | Wait |
| Java | Selenium |
| Static | Dynamic |
28. How to handle dropdown?
Select s = new Select(element);
s.selectByVisibleText(“India”);
29. How to handle alerts?
driver.switchTo().alert().accept();
30. How to take screenshot?
File src = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
TestNG Interview Questions (Important for Test Yantra)
31. What is TestNG?
Testing framework inspired by JUnit.
32. Advantages of TestNG?
- Parallel execution
- Annotations
- Reports
33. Common TestNG annotations?
| Annotation | Purpose |
| @Test | Test case |
| @BeforeMethod | Before each test |
| @AfterMethod | After each test |
34. Priority vs DependsOnMethods?
@Test(priority=1)
@Test(dependsOnMethods=”login”)
35. What is DataProvider?
@DataProvider
public Object[][] data() {
return new Object[][]{{“admin”,”123″}};
}
JUnit Interview Questions
36. Difference between JUnit and TestNG?
| JUnit | TestNG |
| Simple | Advanced |
| No parallel | Supports parallel |
37. JUnit annotations?
- @Test
- @Before
- @After
Framework Design Questions (Very Important)
38. What is POM?
Page Object Model separates test logic and UI elements.
39. POM Example:
@FindBy(id=”username”)
WebElement user;
40. What is Hybrid Framework?
Combination of:
- POM
- Data-driven
- Keyword-driven
41. Tools used in framework?
- Maven
- TestNG
- Jenkins
- Git
- Log4j
42. CI/CD role in automation?
Automates test execution on every build.
Real-Time Interview Scenarios
43. Login scenario validation
- Read data from Excel
- Perform login
- Validate dashboard
44. API + UI validation scenario
- Create user via API
- Validate in UI
- Validate in DB
45. Database validation using Java:
Connection con = DriverManager.getConnection(url, user, pass);
Selenium + Java + API Practical Example
- Use REST Assured for API
- Selenium for UI
- JDBC for DB
- Assert using TestNG
Common Mistakes in Test Yantra Java Interviews
- Weak OOP concepts
- Poor exception handling
- No framework knowledge
- Memorising answers
- No coding practice
1-Page Java Revision Table
| Topic | Key Point |
| OOP | Inheritance, Polymorphism |
| Collections | List, Set, Map |
| Selenium | Locators, Waits |
| TestNG | Annotations |
| Framework | POM, Hybrid |
FAQs (For Google Ranking)
Is Java mandatory for Test Yantra?
Yes, Java is the primary language for automation roles.
What level of Java is asked?
Core Java + automation usage.
Is coding required?
Yes, basic to intermediate coding is mandatory.
Is TestNG compulsory?
Yes, TestNG is heavily used.
