Java Reference
In-Depth Information
line breaks or closing braces to recognize the end of statements. For example, the
compiler considers
System.out.println("Hello")
System.out.println("World!");
a single statement, as if you had written
System.out.println("Hello")
System.out.println("World!");
Then it doesn't understand that statement, because it does not expect the word
System
following the closing parenthesis after
ÑHelloÑ
. The remedy is simple.
Scan every statement for a terminating semicolon, just as you would check that
every English sentence ends in a period.
A
DVANCED
T
OPIC
1.1: Alternative Comment Syntax
In Java there are two methods for writing comments. You already learned that the
compiler ignores anything that you type between
//
and the end of the current line.
The compiler also ignores any text between a
/*
and
*/
.
/*
A simple Java program
*/
The
//
comment is easier to type if the comment is only a single line long. If you
have a comment that is longer than a line, then the
/* È */
comment is simpler:
/*
This is a simple Java program that you can use to try out
your compiler and virtual machine.
*/
It would be somewhat tedious to add the
//
at the beginning of each line and to
move them around whenever the text of the comment changes.
22
23
In this topic, we use
//
for comments that will never grow beyond a line, and
/*
È */
for longer comments. If you prefer, you can always use the
//
style. The
readers of your code will be grateful for any comments, no matter which style you
use.