Getting Started with Java

Comments in Java

Comments help explain your code. Java ignores them.

Single-Line Comments

// This is a single-line comment
System.out.println("Hello!"); // Inline comment

Multi-Line Comments

/* This is a
   multi-line comment */

Documentation Comments (Javadoc)

For generating documentation:

/**
 * This method calculates the sum of two numbers.
 * @param a First number
 * @param b Second number
 * @return The sum of a and b
 */
public int add(int a, int b) {
    return a + b;
}
java
Loading...
Output
Run execution to see output...