Reading and writing I/O streams byte-by-byte is too expensive, as every
write() call refers to the underlying native (JNI) I/O subsystem. Usage of buffered streams reduces the number of native calls and improves I/O performance considerably.
If you override
equals() method in your class, always check if an argument is null. If a null value is passed,
equals() must unconditionally return
NullPointerException should be thrown!).
If a class implements
compareTo() method must return zero if and only if
true for the same non-null argument (and vice versa). Violating this rule may cause unexpected behavior of the objects.
java.util.LinkedList is a special type of collection designed for sequential access (stacks and queues). Being used as a random-accesed array, it is much slower than other List implementations. For instance, getting an item by index (
get(n)) has constant complexity
ArrayLists, while for
LinkedList, the complexity of that operation is
Vector if synchronization is required) for random-accessed lists.
java.net.URL objects used as Map keys or Set items can result in a big performance issue. Internal implementation of
hashCode() methods of java.net.URL class performs domain name resolution, so the time of their execution relies on an internet connection speed. If a computer is off-line, the time is nearly equal to a connection timeout (tens of seconds).
The same problem arises every time when URLs equality checking or hash code computation is performed.
Do not use
java.net.URL to keep URL values. Use
java.net.URI objects or the simple Strings instead.
A common mistake is to retrieve values from a Map while iterating over the Map keys with
Map.get(key) for each entry is expensive and should be avoided for better performance.
entrySet() iterator to avoid the