Lambda Expression, Streams API, Default Methods and Method References. and Repeating Annotations

February 15, 2017
  • what is lambda expression? It is an anonymous function that allows you to pass methods as arguments or simply, a mechanism that helps you remove a lot of boilerplate code.They have no access modifier(private, public or protected), no return type declaration and no name

Java 8 Default Methods

In order to work around situations like this,We will have to provide implementation for sayHi() method in the class MyClass therefore overriding both methods in InterfaceA and InterfaceB.

HashSet vs LinkedHashSet vs TreeSet

February 13, 2017

– HashSet vs LinkedHashSet vs TreeSet

  • Order Of Elements . HashSet doesn’t maintain any order of elements.                                                                     LinkedHashSet maintains insertion order of elements. i.e elements are placed as they are inserted.                              TreeSet orders the elements according to supplied Comparator. If no comparator is supplied, elements will be                      placed in their natural ascending order.

load-balancing in java

February 11, 2017

  • Even Task Distribution Scheme
  • Weighted Task Distribution Scheme
  • Sticky Session Scheme
  • Even Size Task Queue Distribution Scheme
  • Autonomous Queue Scheme

can we initialize a singleton without a private constructor

February 10, 2017


can we initialize without a private constructor, enum

violatile vs atomic keyword

February 1, 2017

Java volatile keyword doesn’t means atomic, its common misconception that after declaring volatile, ++ operation will be atomic, to make the operation atomic you still need to ensure exclusive access using synchronized method or block in Java

Find Duplicates in an Array

January 31, 2017

Given an array of n elements which contains index elements from 0 to n-1, with any of these numbers appearing any number of times. Find these repeating numbers in O(n) and using only constant memory space.

For example, let n be 7 and array be {1, 2, 3, 1, 3, 6, 6}, the answer should be 1, 3 and 6.

Answer-  so basically the in the loop take the element and put a minus sign then when you see the same number it will not be greater than 0, it will be a negative, so it means you encountered the number, so print it , thats the duplicate


for (i = 0; i < size; i++)
if (arr[Math.abs(arr[i])] >= 0)
arr[Math.abs(arr[i])] = -arr[Math.abs(arr[i])];
System.out.print(Math.abs(arr[i]) + ” “);


using collections


public class DuplicateWordSearcher {
public static void main(String[] args) {

    String text = "a r b k c d se f g a d f s s f d s ft gh f ws w f v x s g h d h j j k f sd j e wed a d f";

    List<String> list = Arrays.asList(text.split(" "));

    Set<String> uniqueWords = new HashSet<String>(list);
    for (String word : uniqueWords) {
        System.out.println(word + ": " + Collections.frequency(list, word));

second-highest-or-maximum salary

January 31, 2017

cannot assign a value to final variable

January 4, 2017

when u create a final member you cannot create a setter method

it will throw

cannot assign a value to final variable

by creating a class with private final variables we get immutability anway

instanceof vs getClass()

January 4, 2017

Sreedhar Kannan is the hiring manager. Partha Sarkar will be on the call   for Barclaycard

say for example you have a cat class and then it extends a lion class

then you overwrite a equals() method

then in that you check cat instanceof lion

does it return true or false?


Nomura Reference Data

November 20, 2015

manu kapoor, shawn, kusha

  1. inheritence in hibernate
  2. we have 3 methods m2 is not needed in a transaction how do you do in this in spring transaction, call m1, m2, m3
  3. -if you are reading millions records from a file what datastructure you use to store?then is there any Java 8 features to achieve this faster?

    4. suresh talera wellington
    -if you are using lazy load=true
    then Address inside of Persons are not loaded in Hibernate, but what if you want to check size() on Adrress? what will it give ? nullpointer?then in application, how do you dynamcially load the the Address objects

    5. How many session factories can be created for a given schema?

    6. Types of serialization