Ready to create a quiz? Use Canvas to test your knowledge with a custom quiz Get started
provides a variety of Java-related assessments that focus on work-sample questions
, requiring candidates to solve real-world programming tasks like fixing bugs or writing unit tests. Core Java Practice Questions Common public questions often found on the Java Online Test or in community practice repositories include:
: Write a function to find two indices in an array that add up to a specific target sum. Balanced Parentheses
: Validate a mathematical expression string to ensure all parentheses are correctly closed and nested. Date Conversion
: Convert a user-entered date string (e.g., "12/31/2014") into a specific API format (e.g., "20141231"). Frog Steps
: A dynamic programming problem where you calculate the total number of ways a frog can cover a distance using 1-inch steps or 2-inch jumps. Account Validation testdome java questions and answers
: Use JUnit to write tests ensuring that bank account methods (deposit/withdraw) handle negative numbers and overdraft limits correctly. Specializations and Frameworks also offers specialized tests for more advanced Java roles: Java Online Test | TestDome
Finally, Marcus slid the last paper over. It was a design question involving Interfaces.
"You have a Remote interface and a TV class," Marcus said. "The question asks how to implement a reset method that works for both the TV and a hypothetical Radio class without breaking existing code."
public interface Remote
void turnOn();
void turnOff();
public class TV implements Remote
public void turnOn() System.out.println("TV ON");
public void turnOff() System.out.println("TV OFF");
Elena studied it. "The solution depends on the Java version. If this is Java 7, I have to add the method to the interface and break every implementation that doesn't have it. But assuming a modern environment..."
"Java 8," Marcus confirmed.
"Then I use default methods," Elena said. "It’s one of the most common TestDome questions regarding interfaces. I can add a default implementation so existing classes don't break." Ready to create a quiz
She wrote on the paper:
public interface Remote
void turnOn();
void turnOff();
default void reset()
System.out.println("Resetting device...");
turnOff();
turnOn();
"And," Elena added, tapping the paper, "the beauty of this is that the TV class inherits the behavior automatically, but it can also override reset() if it needs a specific hardware reset sequence."
Marcus finally cracked a smile. "Exactly. Backward compatibility via default methods. Many candidates try to use abstract classes or create a new interface, complicating the hierarchy unnecessarily."
Task: Implement IceCream interface and two classes: Cone and Cup. Each has addScoop(String flavor) and getTotalPrice() where each scoop costs $1.5.
interface IceCream void addScoop(String flavor); double getTotalPrice();abstract class BaseIceCream implements IceCream protected int scoops = 0; public void addScoop(String flavor) scoops++; public double getTotalPrice() return scoops * 1.5;
class Cone extends BaseIceCream {} class Cup extends BaseIceCream {}Question 3: The Interface Dilemma Finally, Marcus slid
public static String reverseCharsInWords(String s)
String[] parts = s.split(" ", -1);
for (int i = 0; i < parts.length; i++)
parts[i] = new StringBuilder(parts[i]).reverse().toString();
return String.join(" ", parts);
public static Map<Integer,Integer> freq(int[] a)
Map<Integer,Integer> m = new HashMap<>();
for (int v : a) m.put(v, m.getOrDefault(v,0)+1);
return m;
public static int[] merge(int[] a, int[] b)
int i=0,j=0,k=0;
int[] res = new int[a.length + b.length];
while (i<a.length && j<b.length)
res[k++] = (a[i] <= b[j]) ? a[i++] : b[j++];
while (i<a.length) res[k++]=a[i++];
while (j<b.length) res[k++]=b[j++];
return res;
public static Character firstNonRepeating(String s)
Map<Character,Integer> m = new LinkedHashMap<>();
for (char c : s.toCharArray()) m.put(c, m.getOrDefault(c,0)+1);
for (Map.Entry<Character,Integer> e : m.entrySet()) if (e.getValue()==1) return e.getKey();
return null;
public static boolean isValid(String s)
Map<Character,Character> pairs = Map.of(')','(',']','[','','');
Deque<Character> st = new ArrayDeque<>();
for (char c : s.toCharArray())
if (pairs.containsValue(c)) st.push(c);
else if (pairs.containsKey(c))
return st.isEmpty();
public static int removeDuplicates(int[] a)
if (a.length==0) return 0;
int write = 1;
for (int read=1; read<a.length; read++)
if (a[read] != a[read-1]) a[write++] = a[read];
return write;
int sum = list.stream().filter(x->x%2==0).mapToInt(Integer::intValue).sum();
Task: Merge two sorted integer arrays into one sorted array. Do not use Arrays.sort().
public class Merger public static int[] mergeSorted(int[] a, int[] b) int[] result = new int[a.length + b.length]; int i = 0, j = 0, k = 0;while (i < a.length && j < b.length) result[k++] = (a[i] <= b[j]) ? a[i++] : b[j++]; while (i < a.length) result[k++] = a[i++]; while (j < b.length) result[k++] = b[j++]; return result;
Unlike LeetCode or HackerRank, TestDome does not just check if your code passes unit tests. Their platform evaluates:
You usually have 20–40 minutes to solve 2–4 questions. The difficulty ranges from intermediate to advanced.