Nice Concepts
#####################################################################################################
Selection among overloaded methods is static (Compile Time), while selection among overridden methods is dynamic
List Vs Set
Set having only one remove(Object) method instead List having two overloaded remove methods 1) remove(int) 2) remove(Object)
You can get the importance of these overloaded remove method from below example
public class SetList {
public static void main(String[] args) {
Set<Integer> set = new TreeSet<Integer>();
List<Integer> list = new ArrayList<Integer>();
for (int i = -3; i < 3; i++) {
set.add(i);
list.add(i);
}
for (int i = 0; i < 3; i++) {
set.remove(i);
list.remove(i);
}
System.out.println(set + ” ” + list);
}
}
Output:
[-3, -2, -1] [-2, 0, 2]
#####################################################################################################
Avoid float and double if exact answers are required
Float and double perform binary floating-point arithmetic, which was carefully designed to furnish accurate approximations quickly over a broad range of magnitudes.
See the example below:
public static void main(String[] args) {
System.out.println(“Float / Double OperationResult: “
+ (1.00 – 9 * .10));
System.out.println(“#################################”);
BigDecimal bd1 = new BigDecimal(“1.00″);
BigDecimal bd2 = new BigDecimal(“0.10″);
BigDecimal bd3 = new BigDecimal(“9″);
System.out.println(“BigDecimal OperationResult: “
+ bd1.subtract(bd2.multiply(bd3)));
System.out.println();
System.out
.println(“Note: Disadvantages to using BigDecimal: it’s less convenient than using a primitive arithmetic type, and it’s slower & Memory Consuming.”);
System.out
.println(“Note: Go for int / long wherever it is possible to use.”);
}