Java Tech columnist Jeff Friesen has been coding in Java for nearly ten years, and in that time, he's found some surprises in the language, like how += doesn't necessarily do what you expect, or the hazards of invoking a potentially overridden method in a constructor. In this article, he provides some important lessons based on this experience.summary:
- Do not use the string concatenation operator in
lengthy loops or other places where performance could suffer.
- Do not call overridable methods from superclass
- Do not use assertions to validate method
ifstatements that explicitly throw
exceptions if those arguments aren't valid.
- Use interfaces for flexibility. Use abstract
classes for ease of evolution or to capture the essence of rigid
class hierarchies while avoiding the creation of objects that mean
- Use covariant return types to minimize upcasting
- Don't forget the superclass while writing a
- Remember that compound assignment operators
automatically include cast operations in their behaviors.