Comments
A comment is a note for people reading the code. The compiler skips it completely, so it never changes what the program does. Java has two kinds:
//starts a comment that runs to the end of the line./*starts a comment that runs until the next*/, even across several lines.
public class Main {
public static void main(String[] args) {
// This is a note. Java skips this line.
System.out.println("Visible");
// System.out.println("Hidden");
/* A block comment
can span several lines. */
System.out.println("Also visible");
}
}
Visible
Also visibleThe fifth line shows a common trick: putting // in front of a statement comments it out. The statement stays in the file, so it's easy to bring back, but it doesn't run. That's handy when you want to try the program without one line.
Inside quotes, // is ordinary text: System.out.println("// not a comment"); prints // not a comment.