This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
The compareTo method of the Comparable interface returns an integer. If the objects are not equal, it does not matter what negative or positive value you return. This flexibility can be useful when comparing integer fields. For example, suppose each employee has a unique integer id, and you want to sort by employee ID number. Then you can simply return id - other.id. That value will be some negative value if the first ID number is less than the other, 0 if they are the same ID, and some positive value otherwise. However, there is one caveat: The range of the integers must be small enough that the subtraction does not overflow. If you know that the IDs are not negative or that their absolute value is at most(Integer.MAX_VALUE - 1) / 2, you are safe.
i got everything in the tip except this part
that their absolute value is at most(Integer.MAX_VALUE - 1) / 2
This is a standard problem with integer arithmetic called overflow; you can overflow positively or negatively. The largest number you can fit into two's complement arithmetic in 8 bits is 0111_1111 (decimal = +127), but if you add 1 you get 1000_0000, which in two's complement is -128. Similarly if you subtract 1 from 1000_0000 (-128) you get 0111_1111 (+127).