HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML

"A Common Coding Style for Java"
Vol. 3, Issue 3, p. 59


Listing 1
Example code demonstrating coding style rules)  
 * @#CodingStyleExample.java        1.0 98/01/23 Achut Reddy  
 * Copyright (c) 1994-1998 Sun Microsystems, Inc. All Rights Reserved.  
package com.sun.examples;  

import java.applet.Applet;  
import java.awt.Point;  
 * A class to demonstrate good coding style.  
public class CodingStyleExample extends Applet implements Runnable {  
    static final int            BUFFER_SIZE = 4096;    // default buffer size  
    StringBuffer             name;                                  // my name  
    Point                         starshipCoordinates[];        // ship locations  
     * Compute the total distance between a set of Points.  
     * @param starshipCoordinates the locations of all known starships  
     * @param numberOfPoints      the number of points in the array  
     * @return the total distance  
    public int computeDistances(Point starshipCoordinates[],  
                                int numberOfPoints) throws Exception {  
        int     distance = 0;   // accumulates distances  
        // Compute distance to each starship and add it to the total  
        for (int i = 0; i < numberOfPoints; i++) {  
            distance += Math.sqrt((double)((starshipCoordinates[i].x *  
                                            starshipCoordinates[i].x) +)  
                                            (starshipCoordinates[i].y *  

        if (distance > 100000) {  
            throw new Exception  

        return distance;  
     * Called whenever Thread.start() is called for this class  
    public void run() {  
         try {  
              name.append  (X);  
         } catch  (Exception  e) {  
              name = new StringBuffer(BUFFER_SIZE);  

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.