java code style

Google Java style

https://google.github.io/styleguide/javaguide.html

  • Source files are encoded in UTF-8.
  • Tab characters are not used for indentation; use two spaces
  • A source file consists of, in order:
  • License or copyright information, if present
  • Package statement
  • Import statements

no wildcard imports

  • Exactly one top-level class

never split overloads classes
always use braces for if,else,for,do and while
style of braces

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
return () -> {
while (condition()) {
method();
}
};

return new MyClass() {
public void () {
if (condition()) {
try {
something();
} catch (ProblemException e) {
recover();
}
} else if (otherCondition()) {
somethingElse();
} else {
lastThing();
}
}
};

line-wrapping normally at 100, but there are exceptions; wrapped lines indent 4+ spaces

  • Exactly one blank line separates each section that is present