Skip to content

Comments

A way to add notes to our code

  • Lesson
  • 1 min read
  • 2 of 15 in this chapter

Why comments are useful

Comments are useful because of the way it allows you to keep notes embedded into your code. In a situation in which code is shared, it helps other programmers understand what is going on in your code.

How to use comments

To add comments use use “//” for one line of comments and “/* */” for multiple lines of comments, for example...

Java
public class HelloWorld {
 public static void main(String[] args) {
 //the line below prints out "hello world"
 System.out.println("Hello World");
 /*the line above is going print out "hello world"
 It will output that code on the screen*/
 }
}