Java Coding Standards

In general we refer to the Suns "Code Conventions for the Java Programming Language" ( http://java.sun.com/docs/codeconv/) for basic syntax and structure of the java code. On this page we will be supplementing the Sun standards with practical modifications and elaborated design principles.

Project folder structure

The folder structure is based on the typical Apache Maven archetype, that is:

  • src/main/java - root folder for java code
  • src/main/resources - folder for resources, such as xml and configuration files
  • src/main/webapp - optional folder for webapp applications webcontent
  • src/test/java - root folder for junit tests
  • src/test/resources - folder for resources used in tests
  • target - root folder for the maven build-area

Code

  • All fields are prefixed with an underscore ("_") to make them easily accessible with autocompletion in your IDE and avoid using the self-keyword.
  • All interfaces should be prefixed with an uppercase "I" (for "interface") so that a class can have the natural name of the interface it is implementing, for example "class Row implements IRow".
  • Always format your code (for example with eclipse's ctrl+shirt+F shortcut) before submitting it.
  • Avoid using abbreviations in class or method names. If it is nescesary though, don't uppercase the whole abbrevation but just the first letter, for example HttpUrl and not HTTPURL!

Testing

We apply this general rule for testing.

  • Test functionality through UnitTesting.
  • Test UI through UI.

Configuring eclipse to support standards

To make the coding standards above work as intended everywhere (including refactoring etc.) the only thing you need to do is add the underscores as prefixes to fields and static fields in eclipse's preferences: Window -> Preferences .. -> Java -> Code Style

A screenshot of the eclipse configuration to comply with JavaCodingStandards

Attachments