Page History
...
- 4-space indents for Java, and 2-space indents for XML. NO TABS ALLOWED.
K&R style braces required. Braces are also required on all blocks.
Code Block if (code) { // code } else { // code }
Maximum length of lines is 120 characters (except for long URLs, packages or imports)
- No trailing spaces allowed (except in comments)
- Do not use wildcard imports (e.g.
import java.util.*
). Duplicated or unused imports are also not allowed. - Write Javadocs for public methods and classes. Keep it short and to the point.
- Javadoc
@author
tags are optional, but should refer to an individual's name or handle (e.g. GitHub username) when included
- Javadoc
Tokens should be surrounded by whitespace, e.g. http://checkstyle.sourceforge.net/config_whitespace.html#WhitespaceAround
Code Block // This is NOT valid. Whitespace around tokens is missing String []={"one","two","three"} // This is valid. Whitespace exists around all tokens String [] = { "one", "two", "three" }
Each line of code can only include one statement. This also means each variable declaration must be on its own line, e.g.
Code Block // This is NOT valid. Three variables are declared on one line String first = "", second = "", third = ""; // This is valid. Each statement is on its own line String first = ""; String second = ""; String third = "";
No empty "catch" blocks in try/catch. A "catch" block must minimally include a comment as to why the catch is empty, e.g.
Code Block try { // some code .. } catch (Exception e) { // ignore, this exception is not important }
All "switch" statements must include a "defaut" clause. Also, each clause in a switch must include a "break", "return", "throw" or "continue" (no fall throughs allowed), e.g.
Code Block // This is NOT valid. Switch doesn't include a "default" and is missing a "break" in first "case" switch (myVal) { case "one": // do something case "two": // do something else break; } // This is valid. Switch has all necessary breaks and includes a "default" clause switch (myVal) { case "one": // do something break; case "two": // do something else break; default: // do nothing break; }
Any "utility" classes (a utility class is one that just includes static methods or variables) should have private constructors, e.g.
Code Block // This is an example class of static constants public class Constants { public static final String DEFAULT_ENCODING = "UTF-8"; public static final String ANOTHER_CONSTANT = "Some value"; // As this is a utility class, it MUST have a private, empty constructor private Constants() { } }
Each source file must contain the required DSpace license header, e.g.
Code Block /** * The contents of this file are subject to the license and copyright * detailed in the LICENSE and NOTICE files at the root of the source * tree and available online at * * http://www.dspace.org/license/ */
...