Comprehensive Guide to Techmojo Java Interview Questions and Answers with Code Examples
Preparing for a Techmojo Java Interview? This comprehensive guide covers 32 common interview questions including Git fundamentals, Java concepts, Selenium automation, REST API testing, SQL queries, and more. Detailed explanations and example code give you the edge to perform confidently in your next technical interview.
1. What is Git and GitHub?
Git is a distributed version control system that helps developers track changes, manage branches, and collaborate with others efficiently.
GitHub complements Git as a cloud-based platform hosting repositories, enabling social coding with pull requests, issues, and integrations.
2. Common Git Commands Used in Projects
git clone <repo-url>
: Clone remote repo locally.git add <file>
: Stage changes for commit.git commit -m "message"
: Commit staged changes.git push origin <branch>
: Push commits to remote.git pull
: Fetch and merge remote changes.git branch
: Manage branches.git checkout <branch>
: Switch branches.
3. Git Command to Modify or Update Code
Modify files locally, then:
git add <file>
git commit -m "Descriptive message"
git push origin <branch>
This sequence updates code safely and tracks history.
4. Git Command to Remove Incorrect Code
git revert <commit>
: Safely undo changes by reverting commits.git reset --hard <commit>
: Reset branch to earlier commit (use with caution).
5. What Are Arrays?
Arrays are fixed-size collections storing elements of the same type at contiguous memory locations, accessible by index.
Example:
int[] numbers = new int[5];
numbers[0] = 10;
numbers[1] = 20;
6. List vs. Set in Java
- List: Ordered, allows duplicates. E.g.,
ArrayList
. - Set: Unordered, no duplicates. E.g.,
HashSet
.
7. What is Map in Java?
A Map stores key-value pairs with unique keys, useful for fast lookups.
Example:
Map<String, Integer> ageMap = new HashMap<>();
ageMap.put("John", 25);
int johnAge = ageMap.get("John");
8. What is POJO?
Plain Old Java Object: simple class with fields, getters, setters; no special inheritance or framework dependencies.
9. What is Configuration and Its Uses?
Externalized parameters (e.g., DB URLs, API keys) configured via files or environment variables for flexible environment management.
Example:
server.port=8080
spring.datasource.url=jdbc:mysql://localhost:3306/mydb
10. Test Scenarios vs. Test Cases
- Scenario: High-level test concept.
- Case: Detailed step-by-step instructions with expected results.
11. Test Scenarios for Login
- Verify valid login succeeds.
- Verify invalid login fails.
- Check forgot password link.
- UI element validations.
- Verify account lockout after failures.
12. Types of Testing
- Functional: Validates features.
- Regression: Checks old features after changes.
- Smoke: Quick build confidence.
- Sanity: Focused tests after minor fixes.
13. REST API vs. SOAP API
- REST: Lightweight, HTTP, JSON/XML formats, stateless.
- SOAP: Strict XML messaging protocol, heavier, enterprise use.
14. Postman Assertion
Scripts that verify API responses, e.g.:
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
15. Build vs. Version
- Build: Code compilation and packaging process.
- Version: Identifier of software state, e.g., 1.0.0.
16. Implicit vs. Fluent Wait in Selenium
- Implicit: Global wait for element discovery.
Example:
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
- Fluent: Customized wait with polling interval and exception handling.
Example:
Wait<WebDriver> wait = new FluentWait<>(driver) .withTimeout(Duration.ofSeconds(30)) .pollingEvery(Duration.ofSeconds(2)) .ignoring(NoSuchElementException.class); WebElement element = wait.until(driver -> driver.findElement(By.id("elementId")));
17. Polymorphism
Ability for objects to take many forms; method overriding and overloading enable flexible code.
18. Method Overloading vs. Overriding
- Overloading: Same method name, different parameters.
- Overriding: Subclass provides new implementation.
19. Encapsulation
Wrapping data and methods together; restricting access with private variables and public getters/setters.
20. Final Keyword in Java
Defines constants, prevents method overriding, or inheritance.
21. Sharing Variable Between Methods
Declare variable at class level (field) to access it in multiple methods.
22. TestNG Annotations Execution Order
@BeforeClass
runs once before all tests.@BeforeMethod
runs before every test method.
23. Usefulness of TestNG
Provides flexible testing, grouping, parallel execution, and detailed reporting.
24. SQL to Count Employees
SELECT COUNT(*) AS EmployeeCount FROM employees;
25. Common JIRA Bug Statuses
- Open
- In Progress
- Resolved
- Closed
- Reopened
- Verified
26. Cross-Browser Testing
Testing application compatibility across browsers using Selenium Grid or cloud services.
27. Frontend vs Backend Testing
- Frontend: UI and responsiveness testing.
- Backend: API, database, and server logic testing.
28. Java Program: Check Palindrome Number
public boolean isPalindrome(int num) {
int original = num, reversed = 0;
while (num != 0) {
int digit = num % 10;
reversed = reversed * 10 + digit;
num /= 10;
}
return original == reversed;
}
29. Java Program: First Non-Repeating Character
public Character firstNonRepeatingChar(String str) {
Map<Character, Integer> counts = new LinkedHashMap<>();
for (char ch : str.toCharArray()) {
counts.put(ch, counts.getOrDefault(ch, 0) + 1);
}
for (Map.Entry<Character, Integer> entry : counts.entrySet()) {
if (entry.getValue() == 1) {
return entry.getKey();
}
}
return null;
}
30. Scrolling in Selenium via JavaScriptExecutor
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("window.scrollBy(0,500)"); // Scroll down by 500 pixels
31. Return Type in Java
Specifies the method’s output data type; can be primitive, object, or void.
32. Return Type for Collection Data
Use collection interfaces like List<T>
, Set<T>
, or Map<K,V>
.
If you want deeper explanations or further examples, feel free to ask!