Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Comments | Getting Started
Introduction to Java
Section 1. Chapter 5
single

single

Comments

Swipe to show menu

Comments are notes inside your code that are completely ignored by the program when it runs. They are meant for humans, not the computer — Java skips them during execution, so they do not affect how your program works in any way.

Despite that, comments are extremely useful. They help you explain what your code is doing, leave reminders for yourself, and make your programs easier to read and understand — especially when they become longer or more complex.

Single-line Comments

A single-line comment starts with //. Everything written after // on the same line is treated as a comment.

Main.java

Main.java

12345678
package com.example; public class Main { public static void main(String[] args) { // This prints a message to the screen System.out.println("Hello!"); } }

Multi-line Comments

When you need to write longer explanations, you can use multi-line comments. These start with /* and end with */. Everything between them is ignored by Java.

public class Main {
   public static void main(String[] args) {
       /*
       This program prints a simple message.
       The comment can span multiple lines.
       Java will ignore everything inside it.
       */
       System.out.println("Hello!");
   }
}

Comments are especially useful in larger programs because they help you understand what different parts of the code are supposed to do without having to analyze everything from scratch.

Task

Swipe to start coding

Your task is to identify the error and comment out the code fragment that contains it.

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 5
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

some-alt