Comments in Java
Explore how to write single-line and multi-line comments in Java to document your code clearly. This lesson helps you understand the syntax and best practices for adding notes to your source code, which improves readability and collaboration in software development.
We'll cover the following...
We'll cover the following...
As a human, it is sometimes useful for us to leave notes in our source code for other humans and even for ourselves. We call these notes comments, and we write them in the following manner:
In the above example, the comments are not printed.
Line 7 and line 8 demonstrate multi-line comments. So, in summary:
- Two forward slashes (
//) mark the start of a single-line comment. - Slash-asterisk (
/*) marks the beginning of a multiple-line comment. - Asterisk-slash (
*/) marks the end of a multiple-line comment.