Browsed by
Category: Java

Lambdas vs Anonymous Inner Classes

Lambdas vs Anonymous Inner Classes

Anonymous inner classes are used by java programmer as “ad hoc” functionality i.e where and when they are needed. Since Java 8, we can use lambda expressions instead of anonymous inner classes. It might seems that both inner classes and lambda expressions are similar as they both are used to implement ad hoc functionality. However there are some differences between lambda expression and inner classes which are as follow.

Read More Read More

HashMap vs ConcurrentHashMap

HashMap vs ConcurrentHashMap

ConcurrentHashMap was introduce with JDK1.5 release to replace legacy class Hashtable. In multithreaded environment ConcurrentHashMap performs better as compared to Hashtable and Synchronized Map as well. All methods of Hashtable are synchronized which makes them quite slow due to contention if a number of thread increases. While ConcurrentHashMap is specially designed for concurrent uses which by default allows 16 threads to simultaneously read and write from map without any external synchronization.

Read More Read More

ArrayList vs Vector

ArrayList vs Vector

Vector is legacy class which is available with Java before collection framework comes into picture while ArrayList was introduce with collection framework. There are some basic differences between ArrayList and Vector as well as few similarities. It is very common to ask question around ArrayList and Vector in interviews. Also if we know the differences and similarities between ArrayList and Vector, it will be easier for us to select one of these while writing our code.

Read More Read More