Java Coding Convention

Improvements? Suggestions? email lif.zone.main+dna@gmail.com

General

Use JS coding conventions, except for the following, use C coding conventions:

  • class definitions: like C struct
  • variables: like C variables
  • field in a class should have m_ prefix
  • static public should NOT have g_ prefix
  • anon class will be declared like anon function in js
  • if overriding method use @Override in line above:
    @Override public void on_change(...) @Override public void on_change(...)
  • no getter or setter need for internal classes
  • private fields in class must be at start of the class (there is an exception when it is the main class of the file)
  • synchronized should be formatted like JS function/catch:
    synchronized (a) { a = 1; } synchronized(a){ a = 1; } synchronized(a){ a = 1; } synchronized(a) { a = 1; b = 1; }
  • classes with a single method can use the JS tiny function style:
    new Thread() { run() { ... } }; new Thread(){ run(){ ... } }; new Thread(){ run(){ ... }}; new Thread(){ run(){ ...; }}; new Thread(){ run(){ ...; }};
  • main class (that the file is named after) content should not be indented