Modern / Recent Platform Additions
The recent platform additions that do not belong to any older topic: JShell, the standard HTTP client, single-file execution, helpful NullPointerExceptions, sequenced collections, and the foreign-memory and vector APIs. Interviewers use them to gauge whether you have kept up past Java 8.
part ofJavaread it →on this pageshowhide
explore
- JShell (REPL)5 questions
- HTTP Client (java.net.http)6 questions
- New String Methods (Java 11+)5 questions
- Single-File Source Execution6 questions
- Helpful NullPointerExceptions5 questions
- Sequenced Collections5 questions
- Foreign Function & Memory API5 questions
- Vector API5 questions
- Release-by-Release Changes7 questions
- Release Train & Preview Stages2 questions
- Class-File API2 questions
- Lazy Constants2 questions
questions
page 2 of 2How do you call a native C function from Java with the Linker (downcall), and what is an upcall?
basics
~20 sA downcall is Java calling into C: you get the Linker, look up the function's address, describe its signature with a FunctionDescriptor, and get a MethodHandle you can invoke. An upcall is the reverse — you wrap a Java method as a function pointer so C can call back into Java.
How do MemoryLayout and VarHandle enable structured, type-safe access to native memory (e.g. reading a C struct)?
basics
~20 sA MemoryLayout describes the shape of memory — the fields, their types, sizes, and offsets — like a blueprint of a C struct. From a layout you derive a VarHandle, a precomputed accessor that reads or writes one field at the right offset, so you don't compute byte offsets by hand.
What out-of-the-box behaviors does the java.net.http client provide for HTTP/2, redirects, timeouts, and authentication?
basics
~20 sThe client speaks HTTP/2 by default (falling back to HTTP/1.1), can follow redirects based on a configured policy, supports a connect timeout on the client and a per-request timeout, and can authenticate via a configured Authenticator or by adding an Authorization header yourself.
Which modern Java features do you use in your own code, and why those?
basics
~20 sA strong answer picks a few and justifies each: records and sealed types with pattern switch for compiler-checked data models, virtual threads for blocking I/O at scale, text blocks for readable literals, and no preview features in production.
What does reversed() return, and how does it behave with respect to the underlying collection?
basics
~20 sreversed() returns a view of the same collection in opposite order, not a copy. It is backed by the original, so reads reflect later changes, and supported writes on the view (like addFirst) modify the original.
What are masks in the Vector API, and how do they let you handle loop tails and conditional (branchless) computation?
basics
~20 sA mask is a per-lane on/off switch. It tells an operation which lanes to actually apply to. You use it to safely process a partial final chunk of an array and to do if-style logic without branches by selecting values per lane.
Why does the FFM API supersede JNI and sun.misc.Unsafe, and what trade-offs and risks should you weigh before adopting it?
basics
~20 sFFM replaces JNI (which needed fragile handwritten C glue) and Unsafe (an internal, crash-prone API) with one safe, pure-Java, standard API. It adds bounds and lifetime safety, no separate C build step, and good performance — but it still crosses a native boundary, needs the right JDK and sometimes runtime flags, and native calls can still crash if signatures are wrong or memory is misused.
What does String.repeat(int) do, and what are its edge cases and uses?
basics
~10 srepeat(n) (Java 11) returns a new string formed by concatenating this string n times. "ab".repeat(3) is "ababab". repeat(0) gives "", and a negative count throws IllegalArgumentException.
What is Java's Class-File API (java.lang.classfile), and why did the JDK add it when ASM already existed?
basics
~20 sThe Class-File API (java.lang.classfile, final in Java 24) is the JDK's standard library for parsing, generating and transforming class files. It exists so tools and the JDK track the class-file format without waiting on a bundled library such as ASM.
What does HTTP/3 change in Java's java.net.http client since JDK 26, and how do you ask for it?
basics
~20 sJDK 26 adds HTTP/3 over QUIC to java.net.http, but it stays opt-in: HTTP/2 remains the default. Set HttpClient.Version.HTTP_3 on the client or the request; sending code is unchanged, and the client still falls back unless told not to.
What is Java's LazyConstant, a preview API at JDK 27, and what does it add over a holder class or double-checked locking?
basics
~20 sLazyConstant, a JDK 27 preview API, runs its computing function at most once, on first get(). Unlike a holder class it works on instance fields; unlike double-checked locking its content can be constant-folded when reached from a static final field.
How does single-file source execution compare with JShell, and when would you choose each?
basics
~20 sJShell is an interactive prompt (REPL) where you type and evaluate code line by line. Single-file execution runs a whole small program from a .java file in one command. Use JShell to explore; use single-file mode to run a script.
In Java's Class-File API, how do models, builders and transforms fit together when rewriting a class, and how does that differ from ASM's visitors?
basics
~20 sImmutable models expose a class as a sequence of elements, builders accept those same elements, and a transform decides for each element whether to keep, drop or replace it. ASM uses one visitor structure for reading and writing, driven by callbacks.
What are the limitations, costs, and security trade-offs of Helpful NullPointerExceptions in production?
basics
~20 sIt only improves the message, never prevents the NPE. Building the message costs a little, but only when an NPE actually happens. The message can include variable names, so don't show it to untrusted users.
How do Helpful NullPointerExceptions compare to other null-handling approaches, and where do they fit in a null-safety strategy?
basics
~10 sThey are a debugging aid, not a prevention tool. You still use Optional, null checks, requireNonNull, and annotations to avoid NPEs; the helpful message just tells you fast where one slipped through.
Why was java.net.http introduced to replace HttpURLConnection, and what does it do better?
basics
~10 sHttpURLConnection is an old, awkward, blocking-only API with no HTTP/2 support. java.net.http replaces it with a modern, immutable builder-based client that supports HTTP/2, WebSocket, async calls via CompletableFuture, and pluggable request/response body handling.
What are forward references in JShell, and how does JShell handle a method that calls something not yet defined?
basics
~20 sA forward reference is when a method you define refers to a variable, method, or type that doesn't exist yet. JShell accepts the definition, marks it as not-yet-runnable, and makes it work automatically once you define the missing piece.
When should you reach for JShell versus a scratch class or unit test, and what are its limits?
basics
~20 sUse JShell for quick, throwaway experiments: trying an API, checking what a snippet returns, or teaching. For anything you need to keep, repeat reliably, or run with your project's dependencies and build, use a scratch class or a unit test instead.
How do List.ofLazy, Map.ofLazy and Set.ofLazy extend LazyConstant, what happens when a computing function throws, and what changed from StableValue?
basics
~20 sList.ofLazy, Map.ofLazy and Set.ofLazy behave like one lazy constant per index, key or candidate. At JDK 27 a throwing function leaves that slot in an error state: NoSuchElementException on each access, never recomputed. JDK 26 turned StableValue into LazyConstant, minus its setters.
What do String.indent(int) and String.transform(Function) do (Java 12), and when would you use each?
basics
~20 sindent(n) (Java 12) adds n spaces of indentation to each line (or removes up to n with a negative value) and normalizes line endings to \n, ensuring each line ends with a newline. transform(fn) applies a function to the whole string and returns its result, letting you chain custom operations fluently.
How do you turn a Java source file into an executable Unix script using single-file execution, and why is the --source flag needed?
basics
~20 sAdd a shebang line #!/path/to/java --source 21 as the first line of an extension-less file, make it executable with chmod +x, and run ./myscript. The --source flag is required because, without a .java extension, the launcher needs to be told to use source mode and which language level.
Why is the Vector API still an incubating module, what does that mean for using it, and how does it relate to Project Valhalla?
basics
~20 sIncubating means it is an unfinished, opt-in module whose API can change between Java releases. You must explicitly enable it. It is waiting on Project Valhalla so vectors can become lightweight value types with no heap overhead before it is finalized.
As a library author, when should you expose SequencedCollection in an API, and what are the trade-offs?
basics
~20 sUse SequencedCollection in a signature when callers genuinely need a defined order plus end access, but you don't want to lock them into List. Accept it as a parameter to be permissive; return it (or a narrower type) when order is part of your contract. Don't use it if order is irrelevant.
Where does single-file source execution sit in Java's evolution toward lower-ceremony programs, and how have JEP 458 and implicit main methods extended it?
basics
~20 sSingle-file execution (Java 11) was an early step to make Java easier for small programs. Later, JEP 458 let you run multi-file programs from source, and implicit classes plus instance main methods removed most boilerplate, so a beginner can run a tiny program from source with almost no ceremony.
As an architect, when should you adopt the Vector API versus relying on JIT auto-vectorization or a native library? What are the costs and risks?
basics
~20 sUse it only for hot, data-parallel numeric kernels where you have measured a real bottleneck and the JIT is not vectorizing reliably. For small or branchy code, let the JIT handle it; for heavy, well-tuned math, a native BLAS library may beat it. Weigh the cost of an unstable, incubating API.
showing 31–55 of 55