Undoubtedly, you want to start your Java career off on the right foot, so let's dive right in and start with the important stuff-comments. Java supports three types of comment delimiters-the traditional /* and */of C, the // of C++, and a new variant that starts with /**and ends with */.
The /* and */delimiters are used to enclose text that is to be treated as a comment by the compiler. These delimiters are useful when you want to designate a lengthy piece of code as a comment, as shown in the following:
/* This is a comment that will span multiplesource code lines. */
The // comment delimiter is borrowed from C++ and is used to indicate that the rest of the line is to be treated as a comment by the Java compiler. This type of comment delimiter is particularly useful for adding comments adjacent to lines of code, as shown in the following:
Date today = new Date(); // create an object with today's dateSystem.out.println(today); // display the date
Finally, the /** and */delimiters are new to Java and are used to indicate that the enclosed text is to be treated as a comment by the compiler, but that the text is also part of the automatic class documentation that can be generated using JavaDoc.
No comments:
Post a Comment