skip to content

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 pageshow

explore

questions

page 2 of 2

How do Helpful NullPointerExceptions compare to other null-handling approaches, and where do they fit in a null-safety strategy?

level: seniorimportance: nice to knowfreq 28%

basics

~10 s

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

open as a page

Why was java.net.http introduced to replace HttpURLConnection, and what does it do better?

level: seniorimportance: nice to knowfreq 40%

basics

~10 s

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

open as a page

What are forward references in JShell, and how does JShell handle a method that calls something not yet defined?

level: seniorimportance: nice to knowfreq 25%

basics

~20 s

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

open as a page

When should you reach for JShell versus a scratch class or unit test, and what are its limits?

level: seniorimportance: nice to knowfreq 22%

basics

~20 s

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

open as a page

What do String.indent(int) and String.transform(Function) do (Java 12), and when would you use each?

level: seniorimportance: nice to knowfreq 35%

basics

~20 s

indent(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.

open as a page

How do you turn a Java source file into an executable Unix script using single-file execution, and why is the --source flag needed?

level: seniorimportance: nice to knowfreq 30%

basics

~20 s

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

open as a page

Why is the Vector API still an incubating module, what does that mean for using it, and how does it relate to Project Valhalla?

level: seniorimportance: nice to knowfreq 22%

basics

~20 s

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

open as a page

As a library author, when should you expose SequencedCollection in an API, and what are the trade-offs?

level: principalimportance: nice to knowfreq 22%

basics

~20 s

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

open as a page

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?

level: principalimportance: nice to knowfreq 22%

basics

~20 s

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

open as a page

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?

level: principalimportance: nice to knowfreq 18%

basics

~20 s

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

open as a page

showing 31–40 of 40