Tags » Best Practise

The Dante 9 circles of hell for organizational development – part I

Just as Dante in the classic 14th-centry poem “Divine Comedy” go through a lot passing the 9 circles of hell, we too have to find our way past many difficulties reaching our objectives when developing our organization. 815 more words

The First Chapters

Methods Common to All Objects(3)

Item 10: Always override toString

Providing a good toString implementation makes your class much more pleasant to use.  When practical, the toString method should return all of the interesting information contained in the object.

Best Practise

Methods Common to All Objects(2)

Item 9: Always override hashCode when you override equals

Equal objects must have equal hash codes.

Do not be tempted to exclude significant parts of an object from the hash code computation to improve performance. 300 more words

Best Practise

Methods Common to All Objects(1)

Item 8: Obey the general contract when overriding equals

The easiest way to avoid problems is not to override the equals method if any of the following conditions apply: 283 more words

Best Practise

Creating & Destroying Objects(7)

Item 7: Avoid finalizers

Finalizers are unpredictable, often dangerous, and generally unnecessary.

  • Never do anything time-critical in a finalizer.
  • Never depend on a finalizer to update critical persistent state.
  • 113 more words
Best Practise

Creating & Destroying Objects(6)

Item 6: Eliminate obsolete object references


// Can you spot the "memory leak"?
public class Stack {
  private Object[] elements;
  private int size = 0;
  private static final int DEFAULT_INITIAL_CAPACITY = 16;

  public Stack() {
    elements = new Object;
  public void push(Object e) {
    elements = e;
  public Object pop() {
    if (size == 0)
      throw new EmptyStackException();
    return elements[--size];

  * Ensure space for at least one more element, roughly
  * doubling the capacity each time the array needs to grow. 90 more words
Best Practise

Creating & Destroying Objects(5)

Item 5: Avoid creating unnecessary objects

  1. An object can always be reused if it is immutable.
String s = new String("stringette"); // DON'T DO THIS!
String s = "stringette"; // DO THIS! 245 more words
Best Practise