Home Sourceforge Page Introduction Specification Design Login Java Style Guide |
Programming Style DocumentVersion 1
In Java there are a few different ways that people arrange their code. I try to make my code as readable as possible, and so this is the style that is used for this project. This style guide is to outline the basic style of code that all programmers must use for this project. BracesCurly braces must go on a new line (both opening and closing). public class Example Not like these: public void getValue() { public void getValue() { return value; } public void getValue() IndentsAll indents are the equivalent of four spaces, but should be represented in a source file as a tab character. NamingClass and method names must start with an upper case letter, variables start with a lower case letter. Classes, variables, and methods should not have underscores denoting spaces - they must be denoted by an upper case letter. Constants are all caps, with underscores denoting spaces. public class NewExample Constants/AttributesConstants are generally public, but can be private. Attributes must always be private. MethodsMethods must always state whether they are public, private or protected - it must not be left out. There is no space between the method name and the first bracket. This applies to calling methods as well as defining them. Control StatementsThe style of control statements is slightly different from methods so as to distinguish the two. For all control statements, there is a space left between the statement and the first bracket. Furthermore, curly braces are always used, even if there is only one statement within the structure. The switch statement uses more indentation than is usually necessary: switch (value) For statements have spaces separating the arguments: for (int i = 0; i < 22; i++) Do and while are fairly straight-forward: do while (value < 22) Try..catch..finally blocksEach keyword is on a new line: try Class structureAll classes must have the same general structure to them, outlined below: Header - file name, class name, author, date, version. |