Testdome Java Questions | And Answers
TestDome Java Questions and Answers
TestDome is a popular platform used by employers to assess practical coding skills. The Java test focuses on object-oriented programming, data structures, algorithms, exception handling, and clean code.
Below are typical TestDome Java problems, ranging from easy to medium/hard difficulty, with solutions and explanations.
1. The "Merge Names" Problem (HashMap & Deduplication)
Prompt: Implement the uniqueNames method. Given two arrays of strings, return a sorted array containing all unique names.
This is the "Hello World" of TestDome Java. It tests collections, sorting, and null-awareness.
Expected Answer:
public class DatabaseConnection private static volatile DatabaseConnection instance;private DatabaseConnection() // private constructor public static DatabaseConnection getInstance() if (instance == null) synchronized (DatabaseConnection.class) if (instance == null) instance = new DatabaseConnection(); return instance; public void query(String sql) // mock database query System.out.println("Executing: " + sql);
Key TestDome checks:
volatilekeyword prevents instruction reordering.- Double-checked locking minimizes synchronization cost.
- Private constructor enforces singleton pattern.
5. Practice the "Sample Questions" First
TestDome offers 4 free Java sample questions. Solve them in a simulated environment before your real screening. Study the "Top solutions" voted by the community.
5. The "Readability Score" Problem (String Manipulation & Regex)
Prompt: Compute the "readability score" as the average number of letters per word. Ignore punctuation. Return the score rounded to two decimal places. testdome java questions and answers
This tests regex, string splitting, and number formatting.
2. Object-Oriented Design (Inheritance & Interfaces)
Sample Question:
Implement a TrainComposition class that models a train where wagons can be added to the left or right, and removed from either end. Use a doubly linked list.
Expected Answer:
import java.util.LinkedList;class TrainComposition private LinkedList<Integer> wagons = new LinkedList<>();
public void attachWagonFromLeft(int wagonId) wagons.addFirst(wagonId); public void attachWagonFromRight(int wagonId) wagons.addLast(wagonId); public int detachWagonFromLeft() if (wagons.isEmpty()) return -1; return wagons.removeFirst(); public int detachWagonFromRight() if (wagons.isEmpty()) return -1; return wagons.removeLast();
TestDome often expects:
- Efficient O(1) operations at both ends.
- Proper handling of empty state (return
-1or throw exception). - Using built-in
LinkedListis acceptable unless prohibited.
Question 6: Caching with Expiry (Medium/Hard)
Task:
Implement a cache that stores key-value pairs with a time-to-live (TTL). After TTL milliseconds, the entry expires and should not be returned.
5. Streams & Lambdas (Java 8+ Focus)
Sample Question:
Given a list of Product objects (name, price, category), return the sum of prices for all products in category "Electronics", but only if the price > 100. Use Java streams. TestDome Java Questions and Answers TestDome is a