Skip to content
On this page

Java

Version

Running Java on OpenJDK v21

Supported languages

Java

Testing framework

JUnit Jupiter 5.9.1

Special reminders and implementation details

java
package challenge;

import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.DisplayName;

@DisplayName("Hello World")
public class HelloWorldTest {
    @Test
	@DisplayName("It should return 'Hello World!'")
    public void testHelloWorld() {
      assertEquals("Hello World!", HelloWorld.helloWorld());
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

Included libraries

How to debug

Debugging Java code is essential for every developer. One of the simplest yet effective ways to debug is by using System.out.println() statements.

Steps to Debug Using System.out.println() Statements

  1. Identify the Problem Area: Locate the section of your code where you suspect the problem might be.

  2. Insert System.out.println() Statements: Add System.out.println() statements before and after the suspected problematic code to print out variable values and flow control.

  3. Check the Results Output of your tests

  4. Analyze the Output: Look at the values printed on the results console to understand what's going wrong in your code. Adjust your code based on the findings and repeat as necessary.

Here’s an example of how to use System.out.println() for debugging:

java
public class DebugExample {
    public static int calculateSum(int a, int b) {
        System.out.println("calculateSum called with arguments: " + a + ", " + b); // Log function call
        int sum = a + b;
        System.out.println("Sum after addition: " + sum); // Log sum calculation
        return sum;
    }

    public static void main(String[] args) {
        int result = calculateSum(5, 10);
        System.out.println("Result of calculateSum: " + result); // Log the result
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13