Thursday, October 1, 2015

JVM - stack, heap etc good explained (link)

http://blog.jamesdbloom.com/JVMInternals.html

JAVA - when WeakReference and SoftReference are equaly garbage collected

WeakReference - is ALWAYS eagerly garbage collected.
SoftReference - is LESS eagerly garbage collected on Server JVM.

The Sun JRE does treat SoftReferences differently from WeakReferences. We attempt to hold on to object referenced by a SoftReference if there isn't pressure on the available memory. One detail: the policy for the "-client" and "-server" JRE's are different: the -client JRE tries to keep your footprint small by preferring to clear SoftReferences rather than expand the heap, whereas the -server JRE tries to keep your performance high by preferring to expand the heap (if possible) rather than clear SoftReferences. One size does not fit all.

More here...

JAVA - collections, the main difference between Map and SortedMap contracts

The main difference between Map and SortedMap contracts is its approach to comparing of keys.

Map contract is to compare keys with equals method.
SortedMap contract is to compare keys with provided or class natural compator.

From javadoc of Comparable<T> interface: This ordering is referred to as the class's natural ordering, and the class's compareTo method is referred to as its natural comparison method.

Objects that implement this interface can be used as keys in a sorted map or as elements in a sorted set, without the need to specify a comparator.

Why NULL can not be set as value in Set?
The natural ordering for a class C is said to be consistent with equals if and only if e1.compareTo(e2) == 0 has the same boolean value as e1.equals(e2) for every e1 and e2 of class C. Note that null is not an instance of any class, and e.compareTo(null) should throw a NullPointerException even though e.equals(null) returns false.