🔧 Setting Up Java — interview questions

10 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.

10 of 10

01A colleague wants to switch a production service from Temurin to Corretto to save on a support contract, and says "it doesn't matter, they're both just OpenJDK." What part of that claim is solid, and what still needs to be checked before shipping the switch?Distributionseasy0-2y02`java -version` reports 21. `javac -version` reports 17. The build fails with errors about syntax that is definitely valid Java 17 and definitely legal in 21. What's actually going on, and why are `PATH` and `JAVA_HOME` both part of the answer?Installationeasy0-2y03A tutorial written for Java 8 in 2015 still compiles and runs correctly today. Why does that backward compatibility hold across a decade, and why doesn't "a new Java version every six months" mean constant forced upgrades for a production team?Versions and editionseasy0-2y04You see three different errors on three different days: `Greet.java:3: error: ';' expected`, `Error: Could not find or load main class Greet`, and a stack trace ending in `ArrayIndexOutOfBoundsException`. How do you tell what kind of problem each one is from the shape of the message alone, and why does the middle one confuse people the most?javac and javaeasy0-2y05A JShell session has a variable `x` set from three lines ago, and it's still usable. Someone in the session calls `System.exit(0)` by accident to see what happens — and the JShell prompt is still there afterward, ready for the next line. What's actually happening under the hood that makes both of those true?JShellmedium3-5y06A class has `public static void main(String[] args)` spelled exactly right, but a teammate insists the JVM "calls main the way any Java code calls a method," with a special compiler-generated hook. Is that accurate, and what actually happens instead?Platform mechanicshard5-8y07A method starts with `if (args == null) { ... }` to guard against no arguments being passed, and a reviewer flags it as dead code that will never run. Are they right, and what actually determines what ends up in `args`?main and its argumentseasy0-2y08A class `com.shop.Order` sits, correctly compiled, inside `out/com/shop/Order.class`, and `java -cp out com.shop.Order` runs it fine. The team then adds JPMS modules to the build, and the exact same class, at the exact same resolvable path, suddenly throws an `IllegalAccessError` from another module's code that references it. What changed, given that the classloader lookup mechanism itself didn't?Packages and the classloaderhard5-8y09A `.class` file is corrupted in transit — a byte gets flipped somewhere in the middle. What actually happens when `java` tries to load it, and why can this failure occur even for a file that `javac` produced correctly and nobody hand-edited?Class file formathard8+y10An IDE underlines an import in red, the developer is confident the class exists, and `mvn test` from the terminal builds clean with no errors. What's actually out of sync, and what's the right fix versus the tempting wrong one?Toolingmedium3-5y