Comments

One of the most important ways to improve the readability of your program is to use comments.

Comments are information included in a program strictly for the benefit of humans trying to figure out what's going on in the program. The Java compiler ignores comments entirely when preparing a runnable version of a Java source file.

There are three different kinds of comments you can use in Java programs, and you can use each of them at your discretion.

The first way to add a comment to a program is to precede it with two slash characters (//). Everything from the slashes to the end of the line is considered a comment, as in the following statement:

int creditHours = 3; // set up credit hours for course

In this example, everything ...

Get Sams Teach Yourself Java 2 in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.