Add experienced-2-3y module: 31 scenario questions (core Java, collections/streams, concurrency, Spring Boot 4.2, JPA N+1, REST problem details, SQL) with 7 asserting tests and 8 transcripts
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b6u469kis46DspusiL
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
4180e746ef
commit
76012dd8c3
@@ -0,0 +1,22 @@
|
||||
== Q1: equals() without hashCode() ==
|
||||
equal points in HashSet (equals only): size = 2
|
||||
equal points in HashSet (record): size = 1
|
||||
== Q2: unboxing null ==
|
||||
int n = map.get("pencil") -> NullPointerException
|
||||
useDefault ? maybe : 0 -> NullPointerException (type of ?: is int)
|
||||
useDefault ? maybe : Integer.valueOf(0) -> null
|
||||
map.getOrDefault("pencil", 0) -> 0
|
||||
== Q3: overridable method in a constructor ==
|
||||
Child.describe sees constantLabel = child, label = null
|
||||
Child.describe sees constantLabel = child, label = child
|
||||
== Q4: defensive copy ==
|
||||
leaky roster after outside changes: [Asha, Ravi, Intruder, Another]
|
||||
safe roster after outside change: [Asha, Ravi]
|
||||
safe roster add -> UnsupportedOperationException
|
||||
== Q5: keep the cause ==
|
||||
without cause: invalid port configuration | cause = null
|
||||
with cause: invalid port configuration | cause = java.lang.NumberFormatException: For input string: "80a"
|
||||
== Q6: sealed interface + pattern switch ==
|
||||
Card[last4=4242] -> card ending 4242
|
||||
Upi[vpa=asha@bank] -> UPI asha@bank
|
||||
Cod[] -> cash on delivery
|
||||
@@ -0,0 +1,21 @@
|
||||
== Q7: TreeSet and a comparator that says 'equal' ==
|
||||
TreeSet by length only: [fig, apple] (3 words added, size 2)
|
||||
length then natural: [fig, apple, grape]
|
||||
== Q8: List<Integer>.remove(int) vs remove(Object) ==
|
||||
remove(1) -> [10, 30]
|
||||
remove(Integer.valueOf(10)) -> [20, 30]
|
||||
== Q9: Collectors.toMap with a duplicate key ==
|
||||
toMap(city, amount) -> IllegalStateException: Duplicate key Pune (attempted merging values 100 and 250)
|
||||
toMap with Integer::sum -> {Mumbai=300, Pune=350}
|
||||
groupingBy + counting -> {Mumbai=1, Pune=2}
|
||||
== Q10: streams are lazy ==
|
||||
no terminal operation: elements touched = 0
|
||||
findFirst() on evens: result = 2, elements touched = 2
|
||||
== Q11: Optional.orElse vs orElseGet ==
|
||||
orElse(expensiveDefault()) -> default computed 1 time(s)
|
||||
orElseGet(expensiveDefault) -> default computed 0 time(s)
|
||||
== Q12: comparator chain with nulls ==
|
||||
Employee[name=Kiran, dept=Eng, salary=80000]
|
||||
Employee[name=Meera, dept=Sales, salary=120000]
|
||||
Employee[name=Asha, dept=Sales, salary=90000]
|
||||
Employee[name=Ravi, dept=null, salary=70000]
|
||||
@@ -0,0 +1,16 @@
|
||||
== Q13: volatile is visibility, not atomicity ==
|
||||
volatile int, 8 threads x 100000 increments: LOST UPDATES (expected 800000)
|
||||
AtomicInteger, same work: 800000
|
||||
== Q14: exceptions inside an ExecutorService ==
|
||||
after submit(): no output yet, future.isDone() = true
|
||||
future.get() -> ExecutionException, cause = java.lang.IllegalStateException: boom from submit
|
||||
uncaught handler on worker: boom from execute
|
||||
== Q15: ConcurrentHashMap is safe per call, not per sequence ==
|
||||
containsKey/put/get sequence: LOST UPDATES (expected 80000)
|
||||
merge(key, 1, Integer::sum): 80000
|
||||
== Q16: ReentrantLock.tryLock with a timeout ==
|
||||
tryLock(50 ms) while another thread holds it -> false
|
||||
tryLock() after the holder released it -> true
|
||||
== Q17: 10,000 blocking tasks on virtual threads ==
|
||||
tasks completed = 10000, ran on virtual threads = 10000
|
||||
finished in under 5 seconds: true
|
||||
@@ -0,0 +1,16 @@
|
||||
== Q18: constructor injection ==
|
||||
Invoice built with plain new and a lambda, no Spring context: total(100) = 110.0
|
||||
Invoice from the context (FlatGst 18%): total(100) = 118.0
|
||||
== Q19: singleton state is shared ==
|
||||
two getBean(SingletonCounter) calls return the same object: true
|
||||
caller A next() = 1, caller B next() = 2
|
||||
two getBean(PrototypeCounter) calls return the same object: false
|
||||
caller A next() = 1, caller B next() = 1
|
||||
== Q20: @Transactional and self-invocation ==
|
||||
TxProbe injected as a Spring proxy: true
|
||||
probe.inner() -> transaction active = true
|
||||
probe.outerCallsInner() -> transaction active = false
|
||||
== Q21: which exceptions roll back ==
|
||||
RuntimeException after save -> rows added = 0
|
||||
checked IOException after save -> rows added = 1
|
||||
checked + rollbackFor = Exception.class -> rows added = 0
|
||||
@@ -0,0 +1,14 @@
|
||||
== Q25: N+1 selects ==
|
||||
data: 5 customers, 12 orders (4 customers x 3 orders, plus one customer with none)
|
||||
lazy loop (default) : total = 2400, SQL statements = 6
|
||||
JOIN FETCH query : total = 2400, SQL statements = 1
|
||||
@EntityGraph("orders") : total = 2400, SQL statements = 1
|
||||
== Q26: LazyInitializationException ==
|
||||
no @Transactional around the loop -> LazyInitializationException
|
||||
message: Cannot lazily initialize collection of role 'com.ankurm.interviewlab.exp23.spring.Customer.orders' with key '1' (no session)
|
||||
== Q27: a DTO projection with LEFT JOIN ==
|
||||
OrderTotal[name=Asha, total=600]
|
||||
OrderTotal[name=Kiran, total=600]
|
||||
OrderTotal[name=Meera, total=600]
|
||||
OrderTotal[name=Nobody, total=0]
|
||||
OrderTotal[name=Ravi, total=600]
|
||||
@@ -0,0 +1,13 @@
|
||||
== Q22: create returns 201 and a Location header ==
|
||||
POST /customers {"name":"Asha"}
|
||||
status = 201
|
||||
Location = /customers/1
|
||||
body = {"id":1,"name":"Asha"}
|
||||
== Q23: bean validation turns into 400 ==
|
||||
POST /customers {"name":"A"} (@Size(min = 2))
|
||||
status = 400
|
||||
body = {"detail":"Invalid request content.","status":400,"title":"Bad Request"}
|
||||
== Q24: a missing resource is a 404 problem response ==
|
||||
GET /customers/99
|
||||
status = 404
|
||||
body = {"detail":"customer 99 not found","status":404,"title":"Customer not found"}
|
||||
@@ -0,0 +1,19 @@
|
||||
data: employee salaries are 120000, 120000, 90000, 80000, 70000 (two people tie for the top)
|
||||
== Q28: second highest salary ==
|
||||
ORDER BY salary DESC OFFSET 1 (no DISTINCT) -> 120000 <- the tie makes this the top salary again
|
||||
SELECT DISTINCT ... OFFSET 1 -> 90000
|
||||
MAX(salary) WHERE salary < MAX(salary) -> 90000
|
||||
DENSE_RANK() = 2 -> 90000
|
||||
== Q29: duplicates ==
|
||||
emails seen more than once:
|
||||
[email protected] x3
|
||||
[email protected] x2
|
||||
DELETE ... NOT IN (SELECT MIN(id) ... GROUP BY email) removed 3 rows; left: [1, 2, 4]
|
||||
== Q30: INNER vs LEFT JOIN, COUNT(*) vs COUNT(col), WHERE vs ON ==
|
||||
departments (id 30 'Ops' has no employees)
|
||||
INNER JOIN departments returned: 2 LEFT JOIN: 3
|
||||
Ops: COUNT(*) = 1, COUNT(e.id) = 0 <- COUNT(*) counts the NULL-extended row
|
||||
LEFT JOIN + WHERE e.salary > 100000 keeps 2 departments; the same filter in ON keeps 3
|
||||
== Q31: what an index changes in the plan ==
|
||||
without an index: SELECT "PUBLIC"."BIG_SIGNUP"."ID", "PUBLIC"."BIG_SIGNUP"."EMAIL" FROM "PUBLIC"."BIG_SIGNUP" /* PUBLIC.BIG_SIGNUP.tableScan */ WHERE "EMAIL" = '[email protected]'
|
||||
with idx_big_email: SELECT "PUBLIC"."BIG_SIGNUP"."ID", "PUBLIC"."BIG_SIGNUP"."EMAIL" FROM "PUBLIC"."BIG_SIGNUP" /* PUBLIC.IDX_BIG_EMAIL: EMAIL = '[email protected]' */ WHERE "EMAIL" = '[email protected]'
|
||||
@@ -0,0 +1,5 @@
|
||||
=== javac NonExhaustiveSwitch.java ===
|
||||
NonExhaustiveSwitch.java:9: error: the switch expression does not cover all possible input values
|
||||
return switch (p) {
|
||||
^
|
||||
1 error
|
||||
Reference in New Issue
Block a user