Sunday, February 9, 2020

Java Interview @ Aricent - Part 2

Hi friends,

In this post, I'm sharing interview questions asked in Aricent 2nd interview. This interview was @ an experience of 12 years.

You can also read actual interview questions asked in other companies:






Question 1:

What is the difference between map and flatMap in Java 8?

Answer:

map() method is used to map an object or entry in stream to some other value.
While flatMap() method , first applies map() on the entries and then flatten the result.

e.g.:
Suppose we have a string array with entries :
String[] strArray = {"12" , "46"};

And we have to find all the permutations of these strings.

So output with map() method will be :  [12, 21] , [46, 64].

While output with flatMap() method will be : [12,21,46,64]


Let's take another example:

List<Integer> evens = Arrays.asList(2,4,6,8);
List<Integer> odds = Arrays.asList(1,3,5,7);
List<Integer> primes = Arrays.asList(5,7,11,13,17);

List numbers = Stream.of(evens, odds, primes).flatMap(list-> list.stream()).collect(Collectors.toList());

System.out.println("List = "+numbers);


O/P: 2,4,6,8,1,3,5,7,5,7,11,13,17


Note: This output is possible only with use of flatMap() method.



Question 2:

What change has been done in HashMap performance in java 8 and how does that change is implemented?

Answer:

In HashMap, a customized LinkedList is used for each entry in underlying bucket. From Java 8, if length of LinkedList gets increased to some threshold, then this LinkedList is converted to Binary Search Tree, which increases performance by reducing search time.

This Binary search tree is constructed using hashcode values of keys. If the hashcode values are different then they are arranged in left or right subtrees. But if the hashcode value is same, in that case there is no such performance improvement.



Question 3:

What is the difference between PUT and PATCH?

Answer:

PUT is used to completely replace a resource at given URI.
While PATCH is used just for partial updation of a given resource at given URI.

Another difference is that while using PUT, we have to send the full payload as the request, while using PATCH , we can only send the parameters which we want to update.



Question 4:

Draw CI/CD pipeline process that you follow in your company.


Answer:




Explanation:

First part is Developer Machine where all the source code and Database scrips are written.
Now all these source code/DB scripts files are pushed to SCM[Source Control Management] like Git/GitHub/GitLab/Azure Repo/Bitbucket etc.

From there it goes to Build pipeline where all this code is compiled and generate a package file for the application [.dll or .jar].

Build Pipeline:

From here CD pipeline starts.

To build the package files, commands like "mvn package install"  or "mvn build" are run .

Also all the unit tests run here.
It also runs static code analyzer tool like Sonarqube.
It also includes configuration for generating scripts.



Release Pipeline:

Here built package files from build pipeline are deployed on multiple servers like QA server, Development server and Production server.
All the Integration tests run here.

QA team takes the build from here and run User Acceptance Testing.
Also deploys SQL scripts on Database server.



Question 5:

What is the upper limit for a payload to pass in the POST method?

Answer:

GET appends data to the service URI. But it's size should not exceed the maximum URL length.
However POST doesn't have any such limit.

So , theoretically , a user can pass unlimited data as the payload to POST method. But, if we consider a real use case, then sending POST with large payload will consume more bandwidth. It will take more time and present performance challenges to the server. Hence, a user should take action accordingly.


Question 6:

Suppose our REST API requires an int value and we send String "abcd" in query parameter , then what response we get?

Answer:

We get error : Not found.

"timestamp": "2019-01-17T18",
"status" : 404,
"error" : "Not found",

"message" : "JSON parse error: Cannot deserialize value of  type int from String \"abcd\": not a valid integer value;
nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException:


Question 7:

What are Spring Core annotations?

Answer:

Spring core annotations are following:

@Qualifier

@Autowired

@Required

@ComponentScan

@Configuration

@Bean

@Lazy

@Value



Question 8:

Explain Spring Data JPA vs Hibernate

Answer:

JPA: Java Persistence API which provide specification for creating, deleting, persisting and data management from java objects to relations [tables] in database.

Hibernate: There are various providers which implement JPA. Hibernate is one of them . So , we have other provider as well e.g.: Eclipse Link etc.

Spring Data JPA: This is another layer on top of JPA which spring provides to make coding easier.




That's all from this interview post.
Hope this post helps everybody in their job interview.

Thanks for reading!!

3 comments:

CAP Theorem and external configuration in microservices

 Hi friends, In this post, I will explain about CAP Theorem and setting external configurations in microservices. Question 1: What is CAP Th...