Code Syntax Guidelines for Java

I expect your code to conform to the following stylistic guidelines.

Indentation:

There are several "acceptable" forms of indentation in the Java world. In general, as long as you are consistent, things should be okay. In general, if you simply allow BlueJ to indent your code, you should be fine. Here're good general examples:

Sample indented text

Identifiers:

Class and interface names should start with a capital letter. All other characters should be lowercase except for those starting another "word". Examples: MattsFirstClass, FuzzyHeadedSkink, etc.

Constant identifiers should consist of all capital letters, with underbars "_" used as word delimiters. Example:

static final int MATTS_WEIGHT = 304; 

All other identifiers (variables, parameters, method names, etc.) start with a lowercase letter. All other characters should be lowercase except for those starting another "word". Examples: mattsFirstMethod, makeASkink, etc.

All identifiers should be mneumonic. So, don't use overly terse identifiers like "i", unless their meaning is very clear. For example, "x" is a very short variable name, but if it is representing part of a Cartesian coordinate, then all is well.

Comments

Every method should have a header comment. This comment should start with a "/**". The block comment should contain a brief description of what the method does, as well as a Javadoc @param statement for each parameter and a @return statement if the method is not void. Here's an example:

  /**
   * Given a move specification, returns a String equivalent.
   * 
   * @param nextMove Sequence of positions (1-32) on the board
   * @return The move sequence as a string
   */
  public static String moveToString(int[] nextMove) {
      String result = "";
      for (int i = 0; i < nextMove.length; i++) {
          result += nextMove[i] + " ";
      }
      return result;
  }

Every class should have a header comment.

/**
 * Demonstrates how text files can by Java programs.
 * @author matt
 *
 */
public class TextFileInputDemo
{
    public static void main(String[] args)
    {
       try
       {
           BufferedReader inputStream = 
              new BufferedReader(new FileReader("morestuff2.txt"));

....
    }

Instance variables :

Instance variables should be declared at the top of each class. Each such declaration should have an in-line comment defining what value that variable holds, unless the name of the variable makes this absolutely clear.

If you want a full description of what the outside world recommends as the coding style for Java you can take a look here. And here is a slightly different style, directly from Google.