Last Updated: December 6, 2025
30 quizzes
Convert a string variable userInput to all uppercase letters before logging it.
String upper = userInput.();Click an option to fill the blank:
Add a constant timeout value to a HashMap in a clear, self-documenting way.
config.put("timeout", String.valueOf());Click an option to fill the blank:
Safely retrieve a value from an Optional<String> named email, providing a default if missing.
String value = email.("unknown@example.com");Click an option to fill the blank:
According to Java coding standards, which is the best name for a constant representing a maximum file size?
Which method name best follows clean code and Effective Java naming guidelines for a method that returns the total price?
Which principle from clean code is most closely related to keeping functions small and focused?
You want a flexible way to add logging behavior to a class without changing its inheritance hierarchy. Which approach is recommended?
Which situation most commonly leads to a NullPointerException in Java?
You frequently add and remove elements in the middle of a list. Which Java collection is generally more efficient?
What is the main benefit of writing unit tests before refactoring code?
In JUnit 5, which annotation marks a method as a test case?
Which practice helps most when debugging a complex issue?
Which statement about performance optimization is most aligned with best practices?
Which JUnit assertion is best to verify that a method throws an IllegalArgumentException?
Order the steps to create and use a JUnit 5 test for a Calculator class.
Drag and drop to reorder, or use the arrows.
Order the steps to debug a failing unit test in an IDE.
Drag and drop to reorder, or use the arrows.
What is the output of this code related to clean code naming?
1public class NamingExample {
2 public static void main(String[] args) {
3 int itemCount = 3;
4 int totalItems = itemCount + 2;
5 System.out.println(totalItems);
6 }
7}What is the output of this code using composition?
1class Logger {
2 private final String name;
3 Logger(String name) { this.name = name; }
4 String format(String msg) { return name + ":" + msg; }
5}
6class Service {
7 private final Logger logger = new Logger("Service");
8 String start() { return logger.format("started"); }
9}
10public class Main {
11 public static void main(String[] args) {
12 Service service = new Service();
13 System.out.println(service.start());
14 }
15}What is the output of this code demonstrating Optional to avoid NullPointerException?
1import java.util.Optional;
2public class OptionalDemo {
3 public static void main(String[] args) {
4 Optional<String> name = Optional.ofNullable(null);
5 String result = name.orElse("guest");
6 System.out.println(result);
7 }
8}What is the output of this JUnit assertion-like logic?
1public class AssertLike {
2 private static boolean equals(int expected, int actual) {
3 return expected == actual;
4 }
5 public static void main(String[] args) {
6 boolean passed = equals(4, 2 + 2);
7 System.out.println(passed ? "PASS" : "FAIL");
8 }
9}Find the bug related to null handling in this code.
Click on the line(s) that contain the bug.
public class UserService { public String getUserName(User user) { return user.getName().toUpperCase(); }}class User { private final String name; User(String name) { this.name = name; } String getName() { return name; }}Find the performance-related bug in this string-building code.
Click on the line(s) that contain the bug.
public class ReportBuilder { public String buildReport(int n) { String report = ""; for (int i = 0; i < n; i++) { report = report + "line" + i + ";"; } return report; }}Match each Java testing concept with its description.
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Match each debugging tool action with what it does.
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Complete the code to define a clean, testable service using composition.
public class EmailService { private final mailSender; public EmailService( mailSender) { this.mailSender = mailSender; } public void sendWelcomeEmail(String address) { mailSender.(address, "Welcome"); }}Click an option to fill blank 1:
Complete the JUnit 5 test to verify that dividing by zero throws an exception.
import org.junit.jupiter.api.Test;import static org.junit.jupiter.api.Assertions.*;class CalculatorTest { @Test void divideByZeroThrows() { Calculator calculator = new Calculator(); (ArithmeticException.class, () -> calculator.(10, )); }}Click an option to fill blank 1:
Complete the code to iterate over a list of orders and calculate the total price cleanly.
import java.util.List;public class OrderService { public double totalPrice(List<Order> orders) { double total = 0.0; for ( order : orders) { total += order.(); } return ; }}Click an option to fill blank 1:
Complete the code to measure response time for a method call.
public class TimingUtil { public static long measure(Runnable task) { long start = System.(); task.(); long end = System.(); return - start; }}Click an option to fill blank 1:
Click the line that will cause a NullPointerException when this code runs.
Click on the line to select.
public class DebugHotspot { public static void main(String[] args) { String value = null; String trimmed = value.trim(); System.out.println(trimmed); }}Click the line that is likely the performance bottleneck due to inefficient collection choice.
Click on the line to select.
import java.util.ArrayList;import java.util.List; public class PerformanceHotspot { public static void main(String[] args) { List<Integer> numbers = new ArrayList<>(); for (int i = 0; i < 100000; i++) { numbers.add(i); } numbers.add(0, -1); System.out.println(numbers.size()); }}