HashMap vs ConcurrentHashMap ArrayList vs LinkedList Optional Optional name = Optional.ofNullable(user); name.ifPresent(System.out::println); String result = name.orElse("Guest"); Find 2nd Highest try without lambda ? int second = arr.stream() .distinct() .sorted(Comparator.reverseOrder()) .skip(1) .findFirst() .orElse(-1); Q7. Time Complexity Operation Complexity Binary Search O(log n) HashMap get O(1) Nested loops O(n²) Merge Sort O(n log n) Quick Sort avg O(n log n) Q9. Injections find others ? @Service class UserService { private final Repo repo; UserService(Repo repo){ this.repo = repo; } } singleton (default) prototype request session find others ? @OneToMany LAZY @ManyToOne EAGER dive deep ? REQUIRED REQUIRES_NEW MANDATORY others ? go through all the use hooks ? useState useEffect Q18. Props vs State Props: Parent → child Immutable State: Internal Mutable explore ? Q20. Virtual DOM React compares: Old Virtual DOM vs New Virtual DOM Updates only differences. Q23. 2nd Highest Salary SELECT DISTINCT salary FROM employee ORDER BY salary DESC OFFSET 1 ROW FETCH NEXT 1 ROW ONLY; Fibonacci int a=0,b=1; for(int i=2;i map = new HashMap<>(); for(char c:s.toCharArray()){ map.put(c, map.getOrDefault(c,0)+1); } checks if any two numbers in an array add up to a given target. arr = [2, 7, 11, 15], target = 9 i=0: diff = 9-2 = 7 → not in map → map={2:0} i=1: diff = 9-7 = 2 → found in map! → return true (2+7=9) Fetch users from API useEffect(() => { fetch("/users") .then(res => res.json()) .then(setUsers); }, []); @Service @Transactional public class PaymentService { public void methodA() { methodB(); } @Transactional(propagation = Propagation.REQUIRES_NEW) public void methodB() { ... } } C. REQUIRES_NEW is ignored due to self-invocation @Transactional(propagation = Propagation.REQUIRES_NEW) on methodB() is completely ignored methodB() runs within the same transaction as methodA() (if any) If methodA() is non-transactional, methodB() also runs without a transactio Option 1: Self-injection @Service @Transactional public class PaymentService { @Autowired private PaymentService self; public void methodA() { self.methodB(); // Goes through proxy } } Option 2: Extract to separate bean @Service public class PaymentService { @Autowired private TransactionalHelper helper; public void methodA() { helper.methodB(); } } @Entity class Order { @OneToMany(mappedBy="order") private List items; } / In a transaction/session Order order = orderRepository.findById(1L); // Transaction commits, session closes // Later, outside transaction List items = order.getItems(); // Proxy still uninitialized int size = items.size(); // ❌ LazyInitializationException thrown Use @Transactional on the method accessing lazy collections Change to FetchType.EAGER (use cautiously - can cause performance issues) Use JOIN FETCH in JPQL: "SELECT o FROM Order o JOIN FETCH o.items WHERE o.id = :id" Initialize explicitly within transaction: Hibernate.initialize(order.getItems()); Question 10 – Banking Scenario You are processing fund transfers. Requirement: Debit Account A Credit Account B If credit fails, debit must rollback. Best approach? @Transactional(propagation = Propagation.REQUIRED) public void transferFunds(Account from, Account to, BigDecimal amount) { debit(from, amount); // Deduct from source credit(to, amount); // Add to destination // If credit fails, debit automatically rolls back }