NOTES of Effective Java (4) – Generics

23. Don’t use raw types in new code 24. Eliminate unchecked warnings 25. Prefer List to Array 26. Favor generic types 27. Favor generic method 28. Use bounded wildcards to increase API flexibility 29. Consider typesafe heterogeneous containers 23. Don’t use raw types in new code Raw type generics is the type without the parameterized [...]

NOTES of Effective Java (8) – Exceptions

57. Use exceptions only for exceptional conditions 58. Use checked exceptions for recoverable conditions and runtime exceptions for programming errors 59. Avoid unnecessary use of checked exceptions 60. Favor the use of standard exceptions 61. Throw exceptions appropriate to the abstraction 62. Document all exceptions thrown by each method 63. Include failure-capture information in detail [...]

C Essence (3) – Linkage

The source code was tested and passed in CentOS 6.4 vagrant box Github repository: http://github.com/allenlsy/c_essence 1. Link multiple target file 2. Definition and Declaration 2.1 extern and static keyword 2.2 Header file 3. Static library 4. Shared library 4.1 Without -fPIC option 4.2 With -fPIC option 4.3 Dynamic linking 4.4 Shared library naming convention 1. [...]

C Essence (2) – C and Assembly

The source code was tested and passed in CentOS 6.4 vagrant box Github repository: http://github.com/allenlsy/c_essence 1. main() and startup routine 2. Storage layout of variablesa 3. C inlines assembly 1. main() and startup routine The command gcc main.c -o main, it actually can be done in three separate steps: gcc -S main.c: compile main.c to [...]

C Essence (1) – x86 Assembly Programming Basic

The source code was tested and passed in CentOS 6.4 vagrant box Github repository: http://github.com/allenlsy/c_essence Reference: 1. Simple assembly program 2. Second assembly program 3. ELF file 3.1 Target file 3.2. Executable file 1. Simple assembly program Suppose we have an assembly program hello.s, and we need to compile and link it.

In this [...]

NOTES of Effective Java (3) – Classes and Interfaces

13. Minimize the accessibility of classes and members 14. In public classes, use accessor methods, not public fields 15. Minimize mutability 16. Favor composition over inheritance 17. Design and document for inheritance or else prohibit it 18. Interface is better than Abstract class 19. Interface for defining type only 20. Prefer class hierarchies to tagged [...]

NOTES of Effective Java (6) – Methods

38. Parameter validation 39. Make defensive copies when needed 40. Design method signatures carefully 41. Use overloading judiciously 42. Use varargs judiciously 43. Return empty arrays or collections, not nulls 44. Write doc comments for all exposed API elements 38. Parameter validation If parameter is not valid, a method should throw exceptions, other than continuing [...]

NOTES of Effective Java (5) – Enum and Annotation

30. Use enums instead of int constants 31. Use instance fields instead of ordinals 32. Use EnumSet instead of bit fields 33. Use EnumMap instead of ordinal indexing 34. Emulate extensible enums with interfaces 35. Prefer annotation to naming patterns(naming convention) 36. Consistenly use the Override annotation 37. Use marker interfaces to define types 30. [...]

NOTES of Effective Java (2) – Methods Common to All Objects

8. Obey the general contract when overriding equals() 9. Always override hashCode when you override equals 10. Always Override toString() 11. Override clone judiciously 12. Comparable interface 8. Obey the general contract when overriding equals() equals() should implement equivalence relation: Reflexive: for any x not null, x.equals(x) should return true Symmetric: for any x, y [...]