Comments

   

Core Java™ 2: Volume I - Fundamentals
By Cay S. Horstmann, Gary Cornell
Table of Contents
Chapter 3.  Fundamental Programming Structures in Java


Comments in Java, like comments in most programming languages, do not show up in the executable program. Thus, you can add as many comments as needed without fear of bloating the code. Java has three ways of showing comments. The most common method is a //. You use this for a comment that will run from the // to the end of the line.

 System.out.println("We will not use 'Hello world!'"); // is this too cute? 

When longer comments are needed, you can mark each line with a //. Or you can use the /* and */ comment delimiters that let you block off a longer comment. This is shown in Example 3-1.

Example 3-1 FirstSample.java
  1. /*  2.    This is the first sample program in Core Java Chapter 3  3.    Copyright (C) 1996...2000 Cay Horstmann and Gary Cornell  4. */  5.  6. public class FirstSample  7. {  8.    public static void main(String[] args)  9.    { 10.        System.out.println("We will not use 'Hello, World!'"); 11.    } 12. } 

Finally, there is a third kind of comment that can be used to generate documentation automatically. This comment uses a /** to start and a */ to end. For more on this type of comment and on automatic documentation generation, please see Chapter 4.

graphics/caution_icon.gif

/* */ comments do not nest in Java. That is, you cannot deactivate code simply by surrounding it with / * and */ since the code that you want to deactivate might itself contain a */ delimiter.


       
    Top
     



    Core Java 2(c) Volume I - Fundamentals
    Building on Your AIX Investment: Moving Forward with IBM eServer pSeries in an On Demand World (MaxFacts Guidebook series)
    ISBN: 193164408X
    EAN: 2147483647
    Year: 2003
    Pages: 110
    Authors: Jim Hoskins

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