    <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/">
     <channel>
        <title>ACCU  :: Java Idioms</title>
        <link>https://members.accu.org/index.php/articles/752</link>
        <description>Professionalism in Programming</description>
        <dc:language>en-us</dc:language> 
        <dc:creator>Administrator</dc:creator> 
        <admin:generatorAgent rdf:resource="http://www.xaraya.org" /> 
        <admin:errorReportsTo rdf:resource="mailto:webeditor@accu.org" />
       <sy:updatePeriod>hourly</sy:updatePeriod>
       <sy:updateFrequency>1</sy:updateFrequency>
       <docs>http://backend.userland.com/rss</docs>




<div class="xar-mod-head"><span class="xar-mod-title">Programming Topics + CVu Journal Vol 11, #1 - Nov 1998</span></div>

<table border="0" cellpadding="1" cellspacing="0">
    <tbody>
    <tr>
        <td valign="top">
            Browse in :
       </td>
       <td valign="top">

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c13/">Topics</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c65/">Programming</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c76/">Journals</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c77/">CVu</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c134/">111</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/c65-134/">Any of these categories</a>

                    -                        <a href="https://members.accu.org/index.php/articles/c65+134/">All of these categories</a>
<br />
</td>
   </tr>
   </tbody>
</table>




<div class="xar-error">
   <p>
 <strong>Note:</strong> when you create a new publication type,
the articles module will automatically use the templates
<em>user-display-[publicationtype].xt</em>
and <em>user-summary-[publicationtype].xt</em>.
If those templates do not exist when you try to preview or display a new article,
you'll get this warning :-)  Please place your own templates in themes/<em>yourtheme</em>/modules/articles . The templates will get the extension .xt there. </p>
</div>
<div class="xar-norm xar-standard-box-padding">
   <h1><strong>Title:</strong>&nbsp;Java Idioms</h1>
<p><strong>Author:</strong>&nbsp;</p>
<p>
<strong>Date:</strong> 03 November 1998 13:15:28 +00:00 or Tue, 03 November 1998 13:15:28 +00:00</p>
<p><strong>Summary:</strong>&nbsp;</p>
<p><strong>Body:</strong>&nbsp;<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e20" id="d0e20"></a>Series
Introduction</h2>
</div>
<p>This series of articles will attempt to present &quot;standard&quot; Java
idioms. It will try to present &quot;best of practice&quot; approaches. As
these are pretty tall claims it would be really useful to receive
feedback either direct email or via C Vu. Any suggestions for
future articles would be greatly appreciated.</p>
<p>The articles will be presented in a standard format:</p>
<div class="variablelist">
<dl>
<dt><span class="term">Name:</span></dt>
<dd>
<p>idiom name</p>
</dd>
<dt><span class="term">Rationale:</span></dt>
<dd>
<p>reason for idiom</p>
</dd>
<dt><span class="term">Advantages:</span></dt>
<dd>
<p>advantages of the idiom</p>
</dd>
<dt><span class="term">Disadvantages:</span></dt>
<dd>
<p>disadvantages of the idiom</p>
</dd>
<dt><span class="term">Description:</span></dt>
<dd>
<p>full description of the idiom including examples</p>
</dd>
</dl>
</div>
<p>Intended articles include:</p>
<div class="itemizedlist">
<ul type="disc">
<li>
<p>javadoc comments</p>
</li>
<li>
<p>code layout</p>
</li>
<li>
<p>exception handling</p>
</li>
<li>
<p>field/method names</p>
</li>
<li>
<p>variable names</p>
</li>
<li>
<p>main in every class</p>
</li>
<li>
<p>modifier order</p>
</li>
<li>
<p>finalizers</p>
</li>
</ul>
</div>
<p>Please note that examples will generally be very contrived for
the purpose of being illustrative rather than demonstrating good
design &#9786;</p>
<p>The articles will generally be applicable to all Java versions.
I'll try to point out any pertinent differences when necessary.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e89" id="d0e89"></a>Java Idioms :
javadoc comments</h2>
</div>
<div class="variablelist">
<dl>
<dt><span class="term">Name:</span></dt>
<dd>
<p>javadoc comments</p>
</dd>
<dt><span class="term">Rationale:</span></dt>
<dd>
<p>self documenting code. Permits the low level interface
documentation to appear inline with the code. This prevents
unnecessary duplication (i.e. separate document duplicating code
comments).</p>
</dd>
<dt><span class="term">Advantages:</span></dt>
<dd>
<p>low-level documentation for interface specifications should
always be up to date.</p>
</dd>
<dt><span class="term">Disadvantages:</span></dt>
<dd>
<p>slightly more time to produce the code (the combined code and
interface specification time should be shorter). Must keep comments
up to date with the source (maintenance issue).</p>
</dd>
<dt><span class="term">Description:</span></dt>
<dd>
<p>There are certain points in a Java source file where javadoc
comments may sensibly be placed. These are:</p>
<div class="itemizedlist">
<ul type="disc">
<li>
<p>before a class or interface specification</p>
</li>
<li>
<p>before a field specification</p>
</li>
<li>
<p>before a method specification</p>
</li>
</ul>
</div>
<p>Note that one can profitably comment all forms of field or
method specification (public, protected, private and package
visibility). Running javadoc with an appropriate option will
produce increasingly more detailed HTML documents. By default
javadoc will generate documentation for the public and protected
fields/methods.</p>
<p><span class="bold"><b>Tags</b></span></p>
<p>The following table lists the javadoc tags and their possible
placements:</p>
<div class="informaltable">
<table border="1" cellspacing="0">
&lt;colgroup&gt;
&lt;col width=&quot;25%&quot;&gt;
&lt;col width=&quot;25%&quot;&gt;
&lt;col width=&quot;25%&quot;&gt;
&lt;col width=&quot;25%&quot;&gt;&lt;/colgroup&gt;
&lt;thead&gt;
<tr>
<th> </th>
<th>class/interface</th>
<th>field</th>
<th>method</th>
</tr>
&lt;/thead&gt;
&lt;tbody&gt;
<tr>
<td>@author</td>
<td>*</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>@version</td>
<td>*</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>@see</td>
<td>*</td>
<td>*</td>
<td>*</td>
</tr>
<tr>
<td>@param</td>
<td> </td>
<td> </td>
<td>*</td>
</tr>
<tr>
<td>@return</td>
<td> </td>
<td> </td>
<td>*</td>
</tr>
<tr>
<td>@exception</td>
<td> </td>
<td> </td>
<td>*</td>
</tr>
<tr>
<td>@since</td>
<td> </td>
<td>*</td>
<td>*</td>
</tr>
<tr>
<td>@deprecated</td>
<td> </td>
<td>*</td>
<td>*</td>
</tr>
&lt;/tbody&gt;
</table>
</div>
<p>Note that @since and @deprecated were introduced in JDK1.1.</p>
<p>The first period terminated sentence should be a short
description of the class/interface, field or method. Watch out when
including a decimal number! This will be used to generated a
summary in the HTML documentation.</p>
<p>For trivial methods the short description along with a possible
more complete description may be sufficient. This is especially
true if the meanings of some parameters are obvious by their name
or even by the method name. In non-trivial methods appropriate
@param and @return (if non-void) should appear. Also if any
exceptions are thrown then they should be documented with an
@exception. One should use the fully qualified class name for the
exception to permit the cross-reference documentation to be
correctly generated.</p>
<p>Although it is unusual to include unchecked exceptions (e.g.
those that extend <tt class=
"classname">java.lang.RuntimeException</tt>) in a method's throws
clause it is good practice for the exceptions to be documented. For
a good example of this see <tt class=
"methodname">java.lang.String#charAt</tt>.</p>
<p>The idiom here is that classes, interfaces, fields and methods
should be sensibly documented. Once one gets into the habit of
typing in javadoc comments as one types the code it becomes second
nature. Failure to do this loses out on one of Java's real
strengths. An important point to note is that to be really useful
the comments must be kept up to date.</p>
</dd>
<dt><span class="term">Example</span></dt>
<dd>
<p>In the <tt class="classname">Point</tt> example the constructor
has commented the parameters. It wasn't really necessary as the
constructor is trivial. In fact in <tt class="methodname">setX</tt>
commenting the parameter would be overkill. The @return in
<tt class="methodname">toString</tt> is for the benefit of the
example.</p>
<p>Note that one can utilise the versioning from the source control
system to give a possible entry for the @version tag.</p>
<pre class="programlisting">
/*
 *  Copyright  (c)  1998  Mark  Kuschnir
 */
package  com.xyz.graphics;
/**
  *  XY  coordinates  of  a  point  in  a  graphical  
  *  coordinate  system.
  *  Only  permit  points  in  the  positive  quadrant:  
  *    x  &gt;=  0  and  y  &gt;=  0.
  *  @author  Mark  Kuschnir
  *  @version  $Revision:  1.1$
  */
  
public  class  Point
{
        /**  X  coordinate.  */        
        private  double  x;
        /**  Y  coordinate.  */
        private  double  y;
        /**
          *  Construct  a  Point  object.
          *  @param  x  X  coordinate
          *  @param  y  Y  coordinate
          *  @exception  java.lang.IllegalArgumentException  
             if  x  &lt;  0  or  y  &lt;  0
          */
          public  Point(double  x,  double  y)
          {
                if  (x  &lt;  0  ||  y  &lt;  0)
                  throw  new  IllegalArgumentException
                              (x+&quot;  &lt;  0  ||  &quot;+y+&quot;  &lt;  0&quot;);
                this.x  =  x;
                this.y  =  y;
          }
         /**
          *  Get  the  X  coordinate.
          */          
        public  double  getX()
        {
                return  (x);
        }        
        /**
          *  Set  the  X  coordinate.
          */          
        public  void  setX(double  x)
        {
                this.x  =  x;
        }        
        //  getY  +  setY  methods
         /**
          *  Return  string  representation  of  the  point.
          *  @return  string  representation
          */
        public  String  toString()
        {
              return (&quot;(&quot;+x+&quot;,&quot;+y+&quot;)&quot;);
        }
    /**
     * Test the class.
     */     
    public static void main(String[] args)
    {
      try
      {
        Point p = new Point(1,2);
        System.out.println(&quot;point = &quot;+p);
        p = new Point(-1,-2);
      }
      catch (Exception e)
      {
        e.printStackTrace();
      }
    }
}
</pre></dd>
</dl>
</div>
</div>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
