. Advertisement .
..3..
. Advertisement .
..4..
Comments in Javascript are used to improve the code’s readability. They offer additional information and explanations about this code. This way, you can find errors, bugs, and maintain the code easily.
This post will discuss the Java block comments and how to insert them.
What Are Comments And Block Comments In Javascript?
There are two types of comments in Java programs. They are documentation comments and implementation ones. The former type is also known as doc comments, which are often delimited by /**…*/.
You can use the javadoc tool to extract them to HTML files. On the other hand, implementation comments can be found in C++. They are often delimited by // and /*…*/.
Those comments are used to comment out codes for a specific implementation. You can also use them to describe the code’s specifications from the implementation-free perspective.
Implementation comments come in four main styles: single-line, end-of-line, block, and trailing. Among them, block comments offer detailed descriptions of the methods, algorithms, files, and data structures.
This type of comment is often inserted at the beginning of the files and before the methods. Yet, you can use it within methods as well. If you use block comments in these places, it would be best to indent them to the same level as the described code.
A blank line is often used before a block comment to set it apart from the code. Use a block comment on multiple code lines at once by using /* and */. Besides being inserted within a statement of the code, block comments will also extend to many lines.
The text among comment delimiters is a remark, which is often disregarded during the compilation process.
Code:
public class multilinecomment {
public static void main(String[] args) {
/* we have declared an integer n having value 007
and a floating point variable z
storing value of pi. */
int n=007;
double z=3.14;
System.out.println(n);
System.out.println(z);
}
}
Output:
7
3.14
In Javascript, you can make use of one more type of multi-line comment with the /** and */. These two commands will enclose the documentation comments.
They can define all formal documentation APIs for such programs created with the javadoc tool. This tool often generates various HTML pages to describe interfaces, methods, classes, constructors, and fields. Besides, it will parse the documentation comments and declarations in a source file collection.
public class javadoccomment {
/** multi() method returns multiplication of numbers.*/
public static int multi(int a, int b){return a*b;}
/** addition() method returns addition of numbers.*/
public static int addition(int a, int b){return a+b;}
/** subtract() method returns subtraction of numbers.*/
public static int subtract(int a, int b){return a-b;}
public static void main(String[] args) {}
}
Use the javadoccomment.java to compile the code and create an HTML file for the javadoccoment class. Then, open the given file and search for the documentation comment in the class.
Conclusion
A Java block comment plays a vital role in explaining and offering information about the code. Thanks to this, you can read the code more easily and precisely.
The above post has explained thoroughly about this type of comment and its uses.
Leave a comment