Limited-Time Offer: Enjoy 50% Savings! Coupon code: 50OFF Use it at checkout
Skip to content

Free Oracle Java SE 11 Developer 1Z0-819 Exam Questions

Last updated: · 11 practice questions with answers and explanations

Page: 1 / 20 Total 296 questions

Want more questions? Get Premium Access.

Question 1

New Single answer

Topic: Working with Java data types

Skill tested: Applies local variable type inference to explicitly typed lambda parameters.

A telemetry service uses Java 11 and must reject malformed records before publishing them. The records are stored in a `List`, and the team wants to use `var` for local variables while retaining a clearly typed lambda parameter for review. Which fragment compiles and preserves the intended filtering behavior?

Correct Answer: B. var accepted = records.stream().filter((record) -> record.length() > 0).collect(java.util.stream.Collectors.toList());
Explanation:

In Java 11, `var` is permitted for a local variable and for an implicitly typed lambda parameter, but a lambda parameter list must be consistently implicit or explicitly typed. Therefore `(record) -> ...` is valid here, and the stream result can be collected with `Collectors.toList()`. `Stream.toList()` was added after Java 11. Mixing `var` with an explicitly typed parameter is illegal, as is mixing `var` and an omitted type in the same parameter list.

Question 2

New Single answer

Topic: Controlling Program Flow

Skill tested: Analyzes switch statement fall-through and break behavior in Java control flow.

A batch importer receives an integer status code for each row. Codes 1 and 2 both require logging the row as accepted, while code 3 requires logging it as rejected. All other values require an invalid-code message. An engineer writes a traditional Java 11 `switch` statement and wants each case to execute only its specified action, with 1 and 2 sharing the accepted action. Which implementation meets that requirement?

Correct Answer: C. `switch (code) { case 1: case 2: logAccepted(); break; case 3: logRejected(); break; default: logInvalid(); }`
Explanation:

Traditional Java 11 switch statements support stacked labels: `case 1:` followed by `case 2:` routes either value to the shared action. The `break` prevents execution from continuing into later cases. In A, code 1 logs acceptance twice and then falls through; in C, code 2 also triggers rejection. D uses comma-separated case labels, syntax introduced for switch expressions in a later Java release, not Java 11.

Question 3

New Multiple answers

Topic: Java Object-Oriented Approach

Skill tested: Selects interface methods and functional-interface structure compatible with Java 11.

A payment integration exposes a single operation that converts a request into a result. The team wants callers to supply that operation with a lambda, while allowing the interface to provide a reusable validation helper and a per-implementation description. The interface must remain a functional interface. Select TWO valid declarations for Java 11.

Correct Answer: A. Declare one abstract method, one `default` instance method, and one `static` method in the interface.; D. Declare one abstract method and one private static helper method in the interface.
Explanation:

A functional interface has exactly one abstract method; default and static methods do not add abstract-method obligations. Java 11 also permits private methods in interfaces, including private static helpers, which can support implementation reuse without becoming part of the public API. A private instance helper is also legal in Java 11, but choice C describes a valid declaration too - however, as written, it is therefore also functionally compatible. The question's requested pair would be ambiguous.

Question 4

New Single answer

Topic: Exception Handling

Skill tested: Uses try-with-resources and suppression behavior when handling resource failures.

A service reads a file using a custom `AutoCloseable` reader. Its `read()` operation throws `IOException`, and `close()` can also throw `IOException`. The service must ensure the reader closes even when reading fails and must preserve the read failure as the primary exception, with any close failure available to diagnostics. Which approach uses Java's built-in resource handling to meet the requirement?

Correct Answer: C. Use `try (Reader r = open()) { r.read(); } catch (IOException e) { log(e); }`; Java records a close failure as a suppressed exception when the body also fails.
Explanation:

Try-with-resources closes the declared resource whether the body completes or throws. If both the body and `close()` fail, the body exception remains primary and the close exception is attached as a suppressed exception, accessible through `getSuppressed()`. A manually written `finally` block can accidentally mask the original failure, as B acknowledges. Skipping close leaks the resource, and multi-catch handles exceptions but does not itself manage resource lifetime.

Question 5

New Single answer

Topic: Working with Streams and Lambda expressions

Skill tested: Groups stream elements by a derived key and computes per-group counts.

A Java 11 service receives a sequential stream of order records. Each record exposes `region()` and `amount()`. The service must produce a map from region to the number of orders in that region; it does not need to retain the records or sum their amounts. Which terminal operation expresses this directly?

Correct Answer: C. `orders.collect(Collectors.groupingBy(Order::region, Collectors.counting()))`
Explanation:

`groupingBy` creates a map keyed by the derived region, and the downstream `counting()` collector produces a count for each key without retaining the orders or aggregating their amounts. `partitioningBy` only divides elements into two Boolean groups. Mapping distinct regions loses the counts. The mutable reduction in D is unsuitable as written for parallel reduction because its combiner discards the second partial map; it also duplicates functionality provided directly by collectors.

Question 6

New Single answer

Topic: Java Platform Module System

Skill tested: Declares module dependencies and exposes packages using Java module descriptors.

A modular application has a `com.acme.app` module that calls public types in `com.acme.catalog`. The catalog module should make only that package accessible to other modules; its implementation package must remain encapsulated. The application must also read the catalog module. Which descriptor arrangement meets these requirements?

Correct Answer: B. In `com.acme.catalog`: `exports com.acme.catalog;`; in `com.acme.app`: `requires com.acme.catalog;`
Explanation:

A module's `exports` directive makes the named package's public types accessible to modules that read it. The consumer declares `requires com.acme.catalog` to read the catalog module. This exports only the requested API package and leaves other packages encapsulated. `opens` primarily enables reflective access rather than ordinary compile-time access. Exporting the implementation package exposes the wrong package, and the dependency/export directions in D are reversed.

Question 7

New Single answer

Topic: Concurrency

Skill tested: Manages task completion and executor lifecycle with ExecutorService.

A command-line application submits a finite batch of independent `Runnable` tasks to a fixed thread pool. It must wait until all submitted tasks have completed before printing a final summary, and then release the executor's resources. The application does not need task results, cancellation, or a deadline. Which sequence is most appropriate in Java 11?

Correct Answer: A. Call `shutdown()`, then repeatedly call `awaitTermination()` until it returns `true`, and only then print the summary.
Explanation:

`shutdown()` stops accepting new tasks but does not wait for already submitted tasks to finish. `awaitTermination()` provides the wait needed before the summary is produced; the loop handles termination not occurring within the first wait interval. `shutdownNow()` attempts to interrupt active tasks and is unnecessary for a normal orderly completion. Discarding futures does not create a completion barrier, and shutdown itself is nonblocking.

Question 8

New Multiple answers

Topic: Java I/O API

Skill tested: Uses NIO file attributes to distinguish regular files from symbolic links.

A cleanup utility scans a directory tree and may delete only regular files that are not symbolic links. It must not follow a symbolic link when determining whether the directory entry itself is a link, and it must leave directories untouched. Which TWO approaches correctly make that determination with Java NIO?

Correct Answer: A. Call `Files.isRegularFile(path, LinkOption.NOFOLLOW_LINKS)` and delete only when it returns `true`.; E. Read `Files.readAttributes(path, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS)` and require `isRegularFile()` and not `isSymbolicLink()`.
Explanation:

Passing `NOFOLLOW_LINKS` to `Files.isRegularFile` evaluates the entry without following a symbolic link, so a link to a regular file is not treated as the target regular file. Reading `BasicFileAttributes` with the same option allows explicit checks of both `isRegularFile()` and `isSymbolicLink()`. The default `isRegularFile` follows links, while a non-directory check also includes links and other file types. `deleteIfExists` does not provide the stated safe type-selection behavior and can delete a symbolic link.

Question 9

New Single answer

Topic: Secure Coding in Java SE Application

Skill tested: Prevents path traversal by validating resolved paths against an authorized directory.

A server lets authenticated users download files beneath a configured document directory. The client supplies a relative file name, and the application runs with filesystem permissions broad enough to access other server files. The service must prevent `..` segments and symbolic path manipulation from escaping the document directory, without relying on a blacklist of suspicious strings. Which design is the strongest fit?

Correct Answer: D. Resolve the name against the base path, normalize it, and require the result to start with the normalized base path; use a filesystem strategy that also prevents symbolic-link escapes when opening the file.
Explanation:

Resolving and normalizing against a trusted base, then checking that the resulting path remains beneath that base, blocks ordinary traversal without fragile string blacklists. Normalization alone does not defeat symbolic links, so the file-opening strategy must also prevent or detect links that redirect outside the authorized tree. A substring blacklist can be bypassed through alternate path forms and does not address links. URL encoding is not a filesystem authorization control, and elevated privileges increase the impact of a flaw.

Question 10

New Single answer

Topic: Database Applications with JDBC

Skill tested: Uses prepared statements to bind untrusted values in JDBC queries.

A Java 11 application searches customer records using a user-supplied email address. The query must return matching records while treating all input strictly as data, including inputs containing quote characters or SQL syntax. The database schema and query structure are fixed, and the team does not need to construct dynamic identifiers. Which JDBC implementation best meets the requirement?

Correct Answer: B. Use `PreparedStatement` with a `?` placeholder for the email and bind it using `setString`.
Explanation:

A `PreparedStatement` keeps SQL structure separate from parameter values. Binding the email with `setString` ensures quote characters and SQL-like content are treated as data rather than executable SQL, which directly satisfies the input-handling requirement. Escaping quotes manually is error-prone and can be context-dependent; stripping punctuation can alter valid input and still does not provide robust query separation. A `CallableStatement` does not provide protection if the application concatenates input into its SQL text.

Question 11

New Single answer

Topic: Localization

Skill tested: Formats monetary values using a locale-specific NumberFormat instance.

A finance application displays a decimal amount to users in several locales. The value must use the locale's currency symbol, grouping separators, and fractional-digit conventions; the stored numeric value must remain unchanged. The application must not construct a formatted string by substituting punctuation manually. Which approach is appropriate?

Correct Answer: A. Create `NumberFormat.getCurrencyInstance(locale)` and format the numeric value for display.
Explanation:

`NumberFormat.getCurrencyInstance(locale)` applies locale-specific currency formatting, including symbol placement, grouping, decimal separators, and appropriate fraction digits. It formats a representation for display without changing the underlying numeric value. A general number formatter does not apply currency conventions. Hard-coding US formatting and replacing punctuation is unreliable because locale rules vary beyond separator characters. `Locale.ROOT` deliberately avoids user-specific conventions, so manually adding a symbol does not meet the requirement.