Comments are an important part of any program. Within them, we can place abbreviated descriptions of the functions we have written and the variables declared. Thanks to them, other people can understand what you were trying to do, with larger projects we can use comments to generate documentation.

Comments are visible only to us, they are skipped during compilation and do not affect the operation of the program.

There are two types of comments in Java:

  • // text – text placed after a doubled slash mark is considered a comment until the end of the line
  • / * text * / – text placed in such tags is treated as a comment by multiple lines of code.

As an example, let’s add comments to our first java program.

Be careful not to accidentally place parts of the code after the comment mark, because it will not be taken into account by the compiler.


Please enter your comment!
Please enter your name here