- Comments are description given by the programmer within the program. So that if another programmer looks at the program,he can easily understand the program by reading the comments.
- The characters or words or anything which are given in comments section won’t be considered by java compiler for compilation process and will be ignored by java compiler during compilation.
Example program for java comments:
Comments can be given in three ways inside a java program. They are,
- Single line comment
- Multi line comment
- Documentation comments
1. Single line comment in Java:
It starts with two forward slashes and continues to the end of the line.
Syntax:
// This comment extends to the end of the line. String welcome = “Hi”; //The text to print |
2. Multi line comment in Java:
Multi line comment starts with forward slash followed by an asterisk, and end with an asterisk followed by a forward slash.
Syntax:
/* This is a comment used for multiple lines */ /* This comment can also be used for single line also */ |
3. Documentation comments in Java:
Documentation comments starts with a forward slash followed by two
asterisks, and ends with an asterisk followed by a forward slash. This
comment contains descriptions about the code and is used to create API
document.
Syntax:
/** This is adocumentation comment */
0 Comments:
Post a Comment