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 ofJavaoverview, primer and where to startread it →on this pageshowhide
explore
- JShell (REPL)5 questions
- HTTP Client (java.net.http)5 questions
- New String Methods (Java 11+)5 questions
- Single-File Source Execution5 questions
- Helpful NullPointerExceptions5 questions
- Sequenced Collections5 questions
- Foreign Function & Memory API5 questions
- Vector API5 questions
questions
page 2 of 2How 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.
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–40 of 40