Browsed by
Category: Interview Questions

Coding Interview Questions

Java Stream

Java Stream

Java Stream API has been introduced in Java 8 which majorly focuses on providing various method for operation on Source.  It operates around Source as wrapper making bulk operation fast and in few lines.

Stream bring functional programming to Java and heavily uses lambda expression for its implementation. ParallelStream can be used for multi-threaded operations.

Stream operations can be classified into two sets

  1. Intermediate Operations
  2. Terminal Operations

Read More Read More

How to avoid null pointer

How to avoid null pointer

The concept of Null Reference is sometimes referred to as “The Billion Dollar Mistake”.  In keeping with modern best practices, you want to eliminate null values from your code.

General rules about null and Option

We begin with the following general rules regarding the use of null values in Scala code:

Read More Read More

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