InterviewSolution
| 1. |
Java Comments |
|
Answer» The statements in a program that are not executed by the compiler and interpreter are referred to as Java comments. Comments can be used to explain and improve the readability of Java code. Comments in a program help to make it more human-readable by putting the details of the code involved, and effective use of comments makes maintenance and bug discovery easier. The following are the different types of comments in Java:
Only one line of code is commented with a single-line comment. It is the most common and straightforward method of commenting on statements. Syntax - // This is a sample comment
Multiple lines of code can be commented with the multi-line comment. Because we must offer '//' at every line to describe a full method in a code or a complex snippet, single-line comments might be tedious to write. To get around this, you can utilise multi-line comments. Between /* and */ are multi-line comments. Java does not execute any text between /* and */. /*This is an Example of multi line comment */
This type of comment is commonly used while writing code for a project/software package because it aids in the generation of a documentation page for reference, which can be used to learn about the methods available, their parameters, and so on. Syntax - /** Comment starts* This is a * Sample comment * comment ends*/ |
|