Published in

Javarevisited

# 17 Java Developer Interview Question Series-9(Experienced candidates 0–6 years)

## Java 8 Stream API:

` Optional<Employee> maxSalaryEmployee =             employeeList.stream()            .collect(Collectors.maxBy(Comparator.comparing(Employee::getSalary)));`

## Polymorphism coding puzzle? Guess the Output?

`public class InheritanceTest {        public static void main(String[] args) {            method(null);        }        public static void method(Object o) {            System.out.println("Object method");        }        public static void method(String s) {            System.out.println("String method");        }}`

## Inheritance Coding problem, guess the output?

`class A{    public void m1() throws ArrayIndexOutOfBoundsException{        System.out.println("In m1 A");    }}class B extends A{     void   m1() throws IndexOutOfBoundsException        {        System.out.println("In m1 B");        }        void m2() throws IndexOutOfBoundsException        {        System.out.println("In m2 B");        }        } public class Test {   public static void main(String[] args) {    A a=new B();    a.m2();}}`

## Write a Program to find a common element from three integer ArrayList. eg. arr1, arr2, and arr3.

`findCommon(int a[], int b[], int c[], int n1, int n2,int n3){    // three sets to maintain frequency of elements    HashSet<Integer> uset = new HashSet<>();    HashSet<Integer> uset2 = new HashSet<>();    HashSet<Integer> uset3 = new HashSet<>();    for (int i = 0; i < n1; i++) {        uset.add(a[i]);    }    for (int i = 0; i < n2; i++) {        uset2.add(b[i]);    }    // checking if elements of 3rd array are present in    // first 2 sets    for (int i = 0; i < n3; i++) {        if (uset.contains(c[i]) && uset2.contains(c[i])) {            // using a 3rd set to prevent duplicates            if (uset3.contains(c[i]) == false)                System.out.print(c[i]+" ");            uset3.add(c[i]);        }    }}`

## What is Method Reference in Java 8?

`ContainingClass::staticMethodName`

# Spring Bean Lifecycle?

--

--

## More from Javarevisited

A humble place to learn Java and Programming better.

## Get the Medium app

I am a Software Developer. I share articles on Java , Spring Boot, Microservices and Cloud.