CSE341 -- Assignments -- Java style guide

Some students have requested more guidance about what we consider acceptable style for the homeworks. Therefore, please observe the following guidelines for the Java project. As always, style rules are guidelines only; there are always exceptions. Use your judgment. -- Keunwoo

Indentation and braces

We will accept any of the standard indent styles: K&R, Allman, Whitesmiths, or GNU/FSF (see here for explanations of the four styles). Please be consistent, at least within a single source file. Also, use at least two spaces for each indent level, and no more than eight.

As an exception, one-liner methods (you will probably have several of these) can be written on one line:

public class Foo 
{
    // ...
    public int getX() { return x; }
}

Naming

Use meaningful names. It is not necessary in Java to abbreviate class names; for example, the Java designers named their input stream class InputStream, not istream. Java programmers are used to long, informative type names, so don't attempt to "save space" by using cryptic identifiers.

The Java convention for capitalization is

Example:

public class ClassName
{
     public static final int CONSTANT_NAME = 0;
     public void methodName(ParamType paramName) {
         VariableType varName = (VariableType)paramName;
     } 
}

However, if you have already started your project using some other naming convention (e.g., C or Ada conventions) then feel free to continue using yours, as long as it's consistent.

It is common in the C++ world to name private instance variables with an initial underscore. This is discouraged in Java.

Comments and documentation

Documentation should take several forms:

See my BufferedCanvas.java file for an example of how to document your classes. We will not expect quite as much documentation for every one of your class files, but it should give you an idea of how to do it.

Code structure

You should use good object-oriented design as described in lectures. Here are some points to remember:


Last modified: Sun May 7 17:28:51 PDT 2000