JPMC Interview Experience | 6 Years | Fullstack Developer | Package 16 LPA

Answers I couldn’t put in video are answered below

Q4.1 There are 100 employees in an ArrayList and I want get all the salaries for employees into another list, How can I leverage streams to do achieve that

Ans:

import java.util.*;
import java.util.stream.*;

public class MainClass {
    
    public static void main(String...as) {
        ArrayList<Employee> list = new ArrayList<>();
        
        // Create emp objects
        Employee emp1 = new Employee("Person1", 10000, "Manager");
        Employee emp2 = new Employee("Person1", 200, "Manager");
        Employee emp3 = new Employee("Person1", 50000, "Manager");
        
        // add to list
        list.add(emp1);
        list.add(emp2);
        list.add(emp3);
        
        // Use stream api to collect all the salaries into another list
        List<Integer> salaries = list.stream().map(emp -> emp.getSalary()).collect(Collectors.toList());
        
        // print
        System.out.println(salaries);
    }
    
    // POJO class
    private static class Employee {
 
     private String name;
     private int salary;
     private String role;
     
     Employee(String name, int salary, String role) {
        this.name = name;
        this.salary = salary;
        this.role = role;
     }
     // Getters and setters
     public int getSalary(){
         return this.salary;
     }
    }
}
Output:

[10000, 200, 50000]

Q5.4 If I want to pass employee data to previous endpoint how many ways are possible?

Ans: Multiple ways we can pass data to an end point, but it entirely depends on the requirement.

For ex

  • If user searching for something from UI then we should use query params.
/api/v1/employees?searchParam=john&age=28
  • If requirement is to create a profile then we need to use POST method and we have pass data in body section.
  • If we are getting data of a user then we can use path parameters.

Q5.5 When to use path params and URL params

Ans: Path params are embedded in path itself where and they don’t have key part, whereas URL params are appended to URL after ? character. and they usually sent in key value pairs

path params: /api/v1/employee/1234

Query Params: /api/v1/employee?name=john

In general path params will be used to target a single object in the datastore for modification or selection or deletion. where as query params are used for search.

both can be interchangeable but in some scenarios like user passes 5-6 filters from UI to search in a table then you don’t want to use path params in there.

Q10.1 Which branching model did you use in previous project?

Ans: Benevolent dictator

Find more info about GIT branching models here Distributed-Git-Distributed-Workflows

Q10.4 Explain what scenario did you use cherry pick?

In some cases we commit code to one feature branch and want to merge same commit to another feature branch. In this case if we raise normal PR it’ll merge all the commits from 1st branch to second branch which we dont want. So in that case first we commit code to first branch and do a cherry pick of that commit alone to second branch.

More info here git-cherry-pick