Comments in Java, as in most other programming languages, are ignored during program execution. Thus, you can add as many comments to the program as needed without fear of increasing its size.
Java has three ways to highlight comments in text. The most common use is two forward slashes
//
, with the comment starting immediately after the characters
//
and continuing to the end of the line.
System.out.println("Hello, Java world!");
If you need longer comments, you can start each line with symbols. Although it is more convenient to limit comment blocks to delimiters
/*
and
*/
.
public class SampleProgram
{
public static void main (String [] args)
{
System.out.println("Hello, Java world!");
}
}
We should not forget that comments, separated by symbols,
/*
cannot
*/
be nested in the Java language. This means that a piece of code cannot be disabled simply by surrounding it with
/*
and , since the code being disabled may itself contain and
*/
delimiters . Link to original source:
Comments in Java/*
*/
GO TO FULL VERSION