Comments are some words, paragraphs or notes in our java file which does not executes. It is used to explain what our code does or why why we should write that piece of code. It helps to make our program more readable and understood by others. Java escapes such comments while executing program. It can also be used to prevent execution when testing alternative code.
Types of comments in Java
- Single Line Comments
- Multi Line Comments
Single line comments
This is used when comments are short and can be written in single line. We can write comment anywhere in program even at the end of code. But once started it will be applied to whole line after that. We start single line comment with //. Here is an example:
Multi line comments
This is used when comments are long and should be written in more than one line. We can start or end comment anywhere in program. Once started it will be applied to whole program until it is stopped. We start multi line comment with /* and end with */. Here is an example:
Variables in Java Previous Next Operators in Java
