Comments In JAVA | Core Java Tutorial | Minigranth
Comments In Java : Introduction
Comments in java are the statements that are ignore by java compiler and hence are not executed.
They are used to describe the program, variable and method used to the other person who is reading the source code.
Also, generation of documentation of a class using documentation comment is one of the feature of comments in java.
Based on the usage, need and features, comments in java can be classified into three types each of which is explained in the later part of this chapter. Let's look at the types first:
Comments In Java : Types
Comments In Java : The Discussion
Single Line Comment
A single line comment is used to comment a single line.
Single line comment starts with //
Consider the example below with a sample program and its respective output.
Single Line Comment : Example
Single Line Comment : The comment line is ignored by the compiler.
Multi- line Comment
Multi line comments are used to comment more than one line.
They start with /* and ends with */
Consider the example below with a sample program and its respective output.
Multi Line Comment : Example
Multi Line Comment : The comment line is ignored by the compiler.
Documentation Comments
Documentation comments are used to generate HTML file that provide documentation of your class.
Documentation comments starts with /** and ends with */
Consider the example below with a sample program and its respective output.
Documentation Comment : Example
Documentation Comment : The comment line is ignored by the compiler.
Note :To generate documentation we use command,javadoc java_file.java