Comments


Every good computer program needs comments to help someone (even the developer) figure out what the code is doing. Java provides three types of comments. The first is the C-based multiline comment. The comment begins with the token /* and ends with the token */ . Everything between these characters is considered a comment and is ignored by the compiler. As the name suggests, multiline comments can span more than one line.

The second type of comment is a single line comment. The token // is placed at the beginning of the comment. This comment cannot span multiple lines. The third type is a documentation comment. The syntax is similar to a multiline comment except it begins with /** . There is a utility that comes with the Java SDK called javadoc . By default, this utility creates HTML files that describe Java source code. (The Sun Java doc pages were created using the javadoc utility.) Documentation comments are incorporated into the HTML files created by javadoc .

Example: Using Comments

 public class CommentDemo {   public static void main(String args[]) {     //  This is a single line comment     /*  This is a comment         that can span more         than one line  */     /**  @author Grant Palmer */   } } 

This example shows the three types of comments in action. The @author syntax is one of the special javadoc tags that can be used with documentation comments. For more information on documentation comments and their associated tags, consult the Sun Java online documentation at http://java.sun.com/j2se/javadoc.



Technical Java. Applications for Science and Engineering
Technical Java: Applications for Science and Engineering
ISBN: 0131018159
EAN: 2147483647
Year: 2003
Pages: 281
Authors: Grant Palmer

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net