Commenting Your Programs

We insert comments to document programs and improve their readability. The Java compiler ignores comments, so they do not cause the computer to perform any action when the program is run.

The comment in line 1

// Fig. A.1: Welcome1.java

begins with //, indicating that it is an end-of-line comment—it terminates at the end of the line on which the // appears. Line 2 is a comment that describes the purpose of the program.

Java also has traditional comments, which can be spread over several lines as in

/* This is a traditional comment. It   can be split over multiple lines */

These begin and end with delimiters, /* and */. The compiler ignores all text between the delimiters.

Get Android™ How to Program, 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.