Abstraction:
- Big programs are built out of small methods.
- Methods can be individually developed,tested and reused.
- User of method does not need to know how it works.
Good programming style
Rule 1: Use good(meaningful) names
1
2
3
4String a1;
int a2;
double b; // BAD!!
String firstName; // GOOD String lastName; // GOOD int temperature; // GOODRule 2: Use indentation
1
2
3
4
5public static void main (String[] arguments) { int x = 5;
x = x * x;
if (x > 20) {
System.out.println(x + “ is greater than 20.”); }
double y = 3.4; }
Ctrl-shift-F to auto-format the file
Rule 3:Use whitespaces
Put whitespaces in complex expressions:1
2
3
4// BAD!!
double cel=fahr*42.0/(13.0-7.0);
// GOOD
double cel = fahr * 42.0 / (13.0 - 7.0);Rule 4:Do not duplicate tests
1
2
3
4if (basePay < 8.0) { ...
} else if (hours > 60) { ...
} else if (basePay >= 8.0 && hours <= 60){ ...
}
—————–BAD—————–
Something about loop
break: terminates a for a while loop
continue: skips the current iteration of a loop and preceeds directly to the next iteration.