Do you like this Article?
Definition :
- Java comments are either explanations of the source code or descriptions of classes, interfaces, methods, and fields.They are usually a couple of lines written above or beside Java code to clarify what it does.
Java has three kinds of comments and they are traditional comments, end-of-line comments and documentation comments. Lets see in detail about it.
Traditional comments :
Traditional comments start with /* and end with */, they may span across multiple lines.Everything in between these two delimiters is ignored by the Java compiler. This type of comments was derived from C and C++.
Example :
End-of-line comments :
End-of-line comments start with // and extend to the end of the current line. The compiler ignores everything from // to the end of the line.
Example :
Documentation comments :
Documentation comments are processed by Javadoc tool to generate documentation from source files. Documentation comment is readable to both, computer and human and to start the comment, use /** instead of and end with */. The JDK javadoc tool uses doc comments when preparing automatically generated documentation.
Example :
This is how comments are created in java and will learn more about this in next tutorial on java comments.
- Java comments are either explanations of the source code or descriptions of classes, interfaces, methods, and fields.They are usually a couple of lines written above or beside Java code to clarify what it does.
Java has three kinds of comments and they are traditional comments, end-of-line comments and documentation comments. Lets see in detail about it.
Traditional comments :
Traditional comments start with /* and end with */, they may span across multiple lines.Everything in between these two delimiters is ignored by the Java compiler. This type of comments was derived from C and C++.
Example :
class Demo {
public static void main(String[] args) {
System.out.println("Hello World!"); /* www.java-answers.blogspot.com */
}
}
End-of-line comments :
End-of-line comments start with // and extend to the end of the current line. The compiler ignores everything from // to the end of the line.
Example :
class Demo {
public static void main(String[] args) {
System.out.println("Hello World!"); //www.java-answers.blogspot.com
}
}
Documentation comments :
Documentation comments are processed by Javadoc tool to generate documentation from source files. Documentation comment is readable to both, computer and human and to start the comment, use /** instead of and end with */. The JDK javadoc tool uses doc comments when preparing automatically generated documentation.
Example :
/**
* Java Answers is a place to get all Java resource
* visit www.java-answers.blogspot.com
*/
class Demo {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
This is how comments are created in java and will learn more about this in next tutorial on java comments.
No comments:
Post a Comment