Programix Logo

Java Source Code Style Guide

[ Back ] [ Programix Home ]

Quick Example:

// Most Javadoc left out for brevity!
import java.io.*;
import java.util.*;

import com.jthreadkit.*;

public class QuickExample extends Object implements Comparable, Serializable {
    public static final int NO_ALIGNMENT = 1;
    private int count;
    private int numStudents;
    private String[] name;

    public QuickExample(
                int param,
                String stuff,
                double otherThings,
                boolean useShortcut
            ) throws IllegalArgumentException {

        this.count = param + 25;
        // ...
    }

    public QuickExample(int param) throws IllegalArgumentException {
        this(param, null, 0.0, true);
    }

    public void someMethod() {
        if ( boolExprA ) {
            // ...
        } else if ( boolExprB ) {
            // ...
        } else {
            // ...
        }

        for ( int i = 0; i < str.length; i++ ) {
            // ...
        }

        while ( blah ) {
            // ...
        }

        synchronized ( this ) {
            // ...
        }

        try {
            // ...
        } catch ( XYZException x ) {
            x.printStackTrace();
        } finally {
            // ...
        }

        switch ( expr ) {
            case 'A':
            case 'X':
                // ...
                break;

            default:
                break;
        }

        button.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    // ...
                }
            });
    }

    /**
     * Calculates the complicated thing and returns the result
     * of the stuff...
     *
     * @return a negative number indicating...
     */
    public int process() {
        // ...
    }

    public static void main(String[] args) {
        // ...
    }
}

Items to take note of:

Other Java style guides:

Sun Microsystems' Source Code Style Conventions (at java.sun.com)
[ Back ] [ Programix Home ]