Java Reference
In-Depth Information
if(x == 5)
System.out.println(“Ternary: yes”);
else
System.out.println(“Ternary: no”);
Java Comments
I have been using comments sporadically in some of the previous examples,
but I have not discussed them yet in detail. There are three techniques for
adding comments to your Java code, each of which has their own particular
usage. The three techniques are the following:
// Use the two forward slashes to comment out text that appears after the
forward slashes but on the same line.
/* and */ Use the /* to turn on comments, and all text will be commented
until a */ is reached. This is useful for commenting out multiple lines of
code.
/** and */ A special type of comment used specifically with the javadoc
tool for generating HTML files that contain your comments. This feature
of Java is widely used, and it is expected that these HTML pages accom-
pany any Java code that is distributed among developers.
The following Television class demonstrates all three types of comments.
The javadoc-style comments will be discussed in detail in Chapter 9,
“Collections.”
/* Filename: Television.java
Author: Rich Raposa
Date: 9/20/02
*/
public class Television
{
private int channel; //current channel
private int prev; //previous channel
/** This method changes the channel
* of this television.
* @param newChannel The channel to be changed to
*/
public void setChannel(int newChannel)
{
prev = channel; //Keep track of the previous channel.
channel = newChannel; //Change to the new channel.
}
}
Search WWH ::




Custom Search