June 11, 2020

Sapient Interview Questions

First Round: Live coding test

1). Asked me to create an employee class with a couple of fields like employee id, date of joining, salary age.

2). Create a couple of employees and add them in a list. Then he asked me to perform operations like filtering, sorting employees based on date of joining, find the employee with maximum salary.(check the blog-post for the answer)

3). He asked me to create a Map, which will contain key as Employee object and value as any random string. Then he asked how it will work? He wanted to check why we need to implement hashCode and equals method, when we are using Employee object as a key?

4). He asked me to create a TreeMap of employees, and asked me what will happen if I use TreeMap instead of a Map? And then he asked me are we supposed to override any other method? TreeMap used compareTo(), he wanted to know what will happen if we do not override compareTo?

5). Then he asked me about synchronization? How it works? Is there any other way to implement synchronization? When I said we can use ReentrantLock.(check the blog-post for the answer)

6). He asked me how ReentrantLock is better then syncronized keyword?(check the blog-post for the answer)

7). Later he told me to explain internal working of ConcurrentHashMap. How the segments are defined in Java and how ReentrantLock is used in the segment.(check the blog-post for the answer)

8). He asked me about immutable classes, and asked me to make my Employee class immutable. He wanted to know, why we need to make class as final, and what is the purpose of declaring variables as final (check the blog-post for the answer)

9). He then asked me to explain Executor framework, told me write a simple program and override call method. (check the blog-post for the answer)

10). He asked about Functional interfaces available in Java 8, purpose of Functional interface. Asked me to write a program using lamda expression, it should take two numbers and return nothing. He wanted to know about BiConsumer functional interface.

11). He asked me who cloning works in Java? Told me to write a program to do deep cloning. He asked whether the Date is mutable or not immutable and how can we create a clone of object, which has a date variable (Employee class has Date of joining).(check the blog-post for the answer)

Wish me luck :)
-K Himaanshu Shuklaa..

No comments:

Post a Comment