Java Programming Style Guide

Good programming style makes your code much more readable and maintainable. Here are some basic style directives that I expect you to follow in your code.

  1. Indent well and use consistent and clear alignment of braces.
  2. Use empty space when appropriate. Separate related sections of code from unrelated sections of code by the use of blank lines.
  3. Comment sections of code that need it. You should use comments to describe a particular twist that might be hard to understand, or to explain what a section of code is doing. If your program has no explanatory comments, you're assuming your readers are more capable than they are.
  4. Break up lines that are longer than 80 characters. This makes your code much easier to read when printed and when listed in a standard terminal window.
  5. Use capitalization and descriptive names to make your identifiers clear.
  6. Keep your methods short. A method shouldn't be longer than 1-2 screens without good reasons.
  7. Each class header should contain comments containing
  8. Each method should contain header comments containing
  9. Your code should be direct and minimal to get the job done. Don't use five variables and three loops when three variables and two loops will get the job done.

This content is a combination of commonly known programming style guidelines, ideas that have been discussed here in our department, and Google's Java style guide.