🧭 Programming Foundations — interview questions

12 questions. Filter by what the role asks for; open one for the six layers of the answer. The course is where the answers come from.

12 of 12

01A beginner writes `x = y; y = x;` expecting to swap two variables, and it does not work. What actually happens, and why does `=` behave this way instead of the way algebra taught them?Language basicseasy0-2y02You get three different Java errors on three different days: `error: illegal start of type`, `Error: Could not find or load main class Foo`, and `Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5`. How do you tell, from the shape of the message alone, what kind of problem each one is — and why can the compiler never catch the third one?Platformeasy0-2y03A method's local variable disappears the instant the method returns, but an object created inside that same method can still be alive minutes later. Why do these two things, created in the same line of code, have such different lifetimes?Memoryeasy0-2y04Someone writes a 'find the second-largest number' function by sorting the whole list and reading off the second element. It works, it passes every test with a small array, and it's noticeably slow once the list has a million entries. What's actually wrong with the approach, and separately — what's the general mistake in assuming the machine will 'figure out' what you meant for an input you didn't think about, like an empty list?Algorithms and problem-solvingmedium3-5y05A mobile client times out waiting for a response to `POST /api/orders`, so it automatically retries the exact same request. What could go wrong, and would the same retry be safe for `PUT /api/orders/42`?HTTPeasy0-2y06A program that used to work now crashes somewhere in a thousand-line file, and nobody knows which recent change broke it. Someone suggests reading the whole file top to bottom to find the bug. Why is that the slow way, and what would a faster method look like?Debuggingmedium3-5y07A payment API returns `{"amountPaid": 19.99, "amountDue": 19.99}`. Both values print as `19.99` after being parsed into Java `double`s, but `amountPaid.equals(amountDue)` sometimes returns `false`. How can two values that print identically compare as unequal, and what's the actual fix?JSONmedium3-5y08Jackson's `ObjectMapper.readValue(json, Order.class)` successfully returns an `Order` object even though the JSON was missing a field the code assumes is always present, and three methods later something throws a `NullPointerException`. Why didn't `readValue` reject the malformed JSON, and how does Jackson actually turn text into an object in the first place?JSONmedium3-5y09Given a subclass `B extends A`, both with static initializer blocks that print, and a program that never mentions `B` until the very last line where it reads `B.name` — why does `A`'s static initializer definitely run before `B`'s, and why does neither run at program start?Platformhard5-8y10A JVM microbenchmark that calls a method once and times it with `System.nanoTime()` reports the method as slow; the same method is fast once the service has been handling real traffic for a minute. What's actually different between those two measurements, and why does HotSpot not just compile everything to machine code immediately at startup?Platformsenior8+y11Two services call each other over HTTP, and a teammate creates a brand-new `HttpClient` on every single outbound call 'to keep things simple.' Why is that a real performance problem, and what is actually happening on the wire before the first byte of an HTTP request is even sent?HTTPhard5-8y12An engineer attaches their IDE's debugger to a JVM running inside a Docker container on a remote host, sets a breakpoint, and it works exactly the way it would locally. What is actually happening over the network to make that possible, and why is an open debug port on a production host a real security hole rather than just a convenience feature left on?Debugginghard5-8y