Version 8 (modified by meddle, 16 years ago) (diff) |
---|
Here we will be adding examples of good code, if you want to add somethings, please talk with the integrators first.
- Example for good equals method.
- You can use the mouse-right-button menu in the source code area of eclipse -> Source -> "Generate hashCode() and equals()..." for template, but refactor it to look like the example bellow:
@Override public boolean equals(Object object) { if (object == null) { return false; } if (object == this) { return true; } if (object.getClass() != this.getClass()) { return false; } // Custom code here... }
- You can use the mouse-right-button menu in the source code area of eclipse -> Source -> "Generate hashCode() and equals()..." for template, but refactor it to look like the example bellow:
- Writing if, else, else if, for, while, do while, try, catch, finally statements, blocks.
- First of all always put curly brackets after the special word that opens the statement, even if the statement contains one row.
if (some_condition) { System.out.println("pass"); }
- Insert spaces between the brackets and the words. The opening bracket of a statement is on the row where the statement is!
while (some_condition) { // something... }
- When writing conditions put spaces between the operands and the operators!
if (a != b) { System.out.println("a is not the same as b"); }
- First of all always put curly brackets after the special word that opens the statement, even if the statement contains one row.