Basic Java Language: Difference between revisions
wikademia>Zchenyu |
wikademia>Zchenyu |
||
| Line 65: | Line 65: | ||
== Comments == | == Comments == | ||
Comments are notes that the developer can insert into their code. This allows the developer to keep track of their code and helps when developers are collaborating on a project. It is good to write a summary of the following code at the beginning of your methods, classes, etc. The Java compiler completely ignores comments, so you can say anything in them | Comments are short notes that the developer can insert into their code. This allows the developer to keep track of their code and helps when developers are collaborating on a project. It is good to write a summary of the following code at the beginning of your methods, classes, etc. The Java compiler completely ignores comments, so you can say anything in them. | ||
Comments are written using two forward slashes | Comments are written using two forward slashes | ||
<pre>//This is a comment</pre> | <pre>// This is a comment</pre> | ||
Comments can be written at the end of a line | Comments can be written at the end of a line | ||
<pre>System.out.println("I love comments"); //This is also a comment</pre> | <pre>System.out.println("I love comments"); // This is also a comment</pre> | ||
Comments can also be written on multiple lines by starting with '''/*''' and ending with'''*/'''. | Comments can also be written on multiple lines by starting with '''/*''' and ending with'''*/'''. | ||
<pre>/* Comment 1 | |||
<pre> | |||
/* Comment 1 | |||
Comment 2 | Comment 2 | ||
Comment 3 */</pre> | Comment 3 | ||
*/ | |||
</pre> | |||
A | A multi-line comment that opens with two asterisks | ||
<pre> | <pre> | ||