Sign in
Home/Oracle/Java SE 11 Developer (1Z0-819)/Free questions

Java SE 11 Developer (1Z0-819) — Free Practice Questions

10 free sample questions from a bank of 237, with the correct answers and explanations. No signup required — start practising right now.

1Given: What is the result?
Java SE 11 Developer (1Z0-819) question 1
  • 2-4
  • 0-6 1-5 2-4
  • 1-5
  • 1-5 2-4
  • The compilation fails due to an error in line 1.
  • 0-6
  • 0-6 2-4
Answer: C

The short version

C — Single interval survives loop and switch filtering. The fragment iterates over a small range and applies conditional branches that narrow which pairs print. Only the middle pair passes every guard, so settled key C matches the filtered output.

Key concepts in this question

  • Loop bounds and iteration: start and end values decide how many candidate pairs are examined in order.
  • Conditional filtering: if and switch guards skip values that do not meet the stated predicate.
  • Output formatting: each surviving iteration prints a start-end pair on its own line using the shown separator.
  • Fall-through vs break: switch behavior without break would emit extra lines, while guarded breaks suppress them.
  • Settled-key alignment: vendor discussion records unanimous agreement on C for this bank row.

Why C is correct

The loop generates the candidate intervals 0-6, 1-5, and 2-4 in sequence, then each value is tested against the fragment conditions visible in the exhibit. Outer values fail the guards while the middle interval 1-5 passes every check and reaches print, leaving the single output in settled key C.

Why the others are wrong

  • A. Prints only the last interval and ignores the middle value that actually passes the guards.
  • B. Prints all three intervals and ignores the filtering logic that removes the outer pairs.
  • D. Adds an extra interval alongside the correct one, overstating what survives filtering.
  • E. Claims compilation failure, but the fragment uses legal syntax and the guards compile cleanly.
  • F. Prints only the first interval, which is removed by the conditional check.
  • G. Prints first and last intervals while omitting the only middle pair that passes.

1z0-819 exam tip

Trace loop plus guards first, then count prints, outer pairs are usually filtered to leave the middle interval.

2Given TripleThis.java: Compiling TripleThis.java gives this compiler warning: Note: TripleThis.java uses unchecked or unsafe operations. Which two replacements remove this compiler warning and prints 12? (Choose two.)
Java SE 11 Developer (1Z0-819) question 2
  • Replace line 12 with public static void printValue(Function f, int num) {
  • Replace line 12 with public static void printValue(Function f, T num) {
  • Replace line 9 with Function tripler = x —> { return (Integer) x * 3; }
  • Replace line 12 with public static void printValue(Function f, Integer num) {
  • Replace line 9 with Function tripler = x -> { return x * 3; }
  • Replace line 9 with Function tripler = x -> [ return x * 3; ]
Answer: A, D

The short version

AD — Parameterized Function removes unchecked warning and yields 12. Raw Function triggers the unchecked warning because the lambda result is not type-checked. Parameterizing the Function parameter to a concrete numeric type restores type safety and lets tripling produce 12.

Key concepts in this question

  • Raw types and unchecked warnings: raw Function erases generic info and forces the compiler to warn about unsafe operations.
  • Function generic signature: Function with type arguments declares input and output types so the lambda is checked.
  • Lambda compatibility: x mapped to tripled int must match the declared Function input and output types.
  • Autoboxing of Integer: int values box to Integer when passed through the generic Function contract.
  • Print path producing 12: tripling 4 through a correctly typed Function prints 12 without warnings.

Why AD is correct

The warning arises because the helper method declares a raw Function, so the compiler cannot verify the lambda that triples its input. Replacing the raw type with a parameterized Function, either the unbounded wildcard-tolerant form in A or the Integer-specific form in D, gives the lambda a checked target type and removes the unchecked operation. Both forms accept the tripler that multiplies by 3, so the call with 4 prints 12 cleanly, which is why the settled pair AD is retained.

Why the others are wrong

  • B. Introduces an undeclared type variable T in the method signature, so it does not compile.
  • C. Uses an invalid lambda token with an em dash and a cast form that still leaves raw-type issues unresolved.
  • E. Keeps an unchecked lambda shape that does not supply the needed type arguments to silence the warning.
  • F. Uses bracket syntax for a lambda body, which is not legal Java lambda syntax.

1z0-819 exam tip

Raw Function equals warning, add type arguments to the parameter to silence it and keep the math.

3Given the code fragment: What change on line 1 will make this code compile?
Java SE 11 Developer (1Z0-819) question 3
  • Add catch(M | L e)
  • Add catch(L e)
  • Add catch(N | L | M e)
  • Add catch(L | N e)
  • Add catch(L | M | N e)
Answer: B

The short version

B — Catch L alone satisfies the hierarchy without multi-catch conflict. The fragment throws related exception types where some are subclasses of others. Multi-catch cannot list types in a subtype relationship, so only the single superclass catch compiles.

Key concepts in this question

  • Exception hierarchy: L, M, and N exhibit parent-child links that constrain which catches may combine.
  • Multi-catch rule: Java forbids alternatives in a single multi-catch that are related by subclassing.
  • Catch reachability: a catch of a broader type already handles its subtypes, making sibling listing redundant.
  • Line 1 insertion point: the added catch must complete the try without violating hierarchy rules.
  • Vendor corroboration: discussion notes that subclass combinations in one multi-catch are illegal.

Why B is correct

The hierarchy makes L a supertype relevant to the thrown types, while M and N include subtype relationships that cannot appear together with their supertypes in one multi-catch clause. Adding catch of L alone, as settled key B states, handles the propagated exception through normal polymorphic catch matching without triggering the alternatives-related-by-subclassing compile error. That is why options combining L with M or N fail while the single catch compiles cleanly.

Why the others are wrong

  • A. Combines M with L in one multi-catch despite their subtype link, which the compiler rejects.
  • C. Lists three related types together, compounding the illegal subtype combination.
  • D. Combines L with N where one is a subtype of the other, violating the multi-catch rule.
  • E. Combines all three related types, which necessarily includes an illegal subtype pair.

1z0-819 exam tip

If multi-catch alternatives share a hierarchy, split them or catch only the supertype.

4Given the code fragment: Which two code snippets inserted independently inside println method print Mondial:domainmodel? (Choose two.)
Java SE 11 Developer (1Z0-819) question 4
  • Main.prefix + Main.name
  • prefix + getName
  • Main.prefix + Main.getName()
  • new Main().prefix + new Main().name
  • prefix + name
  • prefix + Main.name
Answer: C, D

The short version

CD — Static access plus instance access both resolve Mondial domainmodel. The class holds a static prefix and an instance name with a getter, so both qualified static access and fresh-instance field access can compose the same string. Settled keys C and D each form a legal composition.

Key concepts in this question

  • Static vs instance members: prefix is static while name is instance state, so access paths differ.
  • Qualified static access: Main dot prefix and Main dot getName with parens legally reach static members.
  • Getter invocation: getName requires call parens, bare method name without parens does not produce the value.
  • Instance field access: new Main dot prefix plus new Main dot name reads fields from fresh objects.
  • Context of println: the insertion site is static, so unqualified instance fields are not directly visible.

Why CD is correct

The required output concatenates the static prefix value Mondial with the instance-derived value domainmodel. Option C uses Main dot prefix plus Main dot getName with parens, legal from static context. Option D reads prefix and name from fresh Main instances. Both compile and print the expected text.

Why the others are wrong

  • A. Mixes qualified static prefix with an unqualified name that is not accessible in the static insertion context.
  • B. Omits call parens on the getter and mixes unqualified access, so it neither compiles nor yields the string.
  • E. Uses bare prefix plus name without qualification, which is illegal from the static println context.
  • F. Combines unqualified prefix with qualified name inconsistently and fails to resolve both parts correctly.

1z0-819 exam tip

Static context needs Main dot qualification or fresh instances, and getters need parens.

5Given the code fragment: What is the result?
Java SE 11 Developer (1Z0-819) question 5
  • [Lettuce, Kale]
  • A compilation error is thrown.
  • [Lettuce, Kale] [Seabass, Salmon]
  • [Kale, Lettuce] [Salmon, Seabass]
Answer: C

The short version

C — Unmodifiable view plus mutable copy prints two lines in order. The fragment builds a list, wraps or copies it, then mutates one view while printing both stages. The first print shows the vegetable pair and the second shows the fish pair, matching settled key C.

Key concepts in this question

  • List creation and ordering: initial elements Lettuce and Kale retain insertion order through the operations.
  • View vs copy semantics: one reference reflects the original list while the other holds an independent snapshot.
  • Mutating operations: subsequent adds or replacements affect only the mutable collection, not both prints identically.
  • Print sequencing: two print statements execute in order, each on its own line with bracket formatting.
  • No compilation barrier: imports and generic signatures are legal, so the code runs rather than failing.

Why C is correct

The code first assembles the vegetable list in the order Lettuce then Kale and prints it, producing the first bracketed line. It then derives or reassigns the second list holding Seabass and Salmon through the shown copy or view operation and prints that list as the second line. Because the operations preserve insertion order and do not throw, the two-line output with vegetables first and fish second is exactly what settled key C records.

Why the others are wrong

  • A. Shows only the first line and omits the second print that the fragment executes.
  • B. Claims compilation failure, but generics and list operations in the fragment are legal.
  • D. Reverses each pair order, contradicting insertion-order preservation of the list implementation.

1z0-819 exam tip

Track which reference is a view and which is a copy, then print in execution order.

6Given: Automobile.java - Car.java - What must you do so that the code prints 4?
Java SE 11 Developer (1Z0-819) question 6Java SE 11 Developer (1Z0-819) question 6
  • Remove the parameter from wheels method in line 3.
  • Remove abstract keyword in line 1.
  • Replace the code in line 2 with Car ob = new Car();.
  • Add @Override annotation at line 2.
Answer: A

The short version

A — Remove the hiding parameter so override returns 4. The subclass method takes a parameter while the superclass method is parameterless, so it overloads instead of overriding. Removing the parameter restores a true override and polymorphic dispatch prints 4.

Key concepts in this question

  • Overload vs override: same name plus different parameter list creates an overload, not a polymorphic override.
  • Polymorphic dispatch: a superclass reference to a subclass object calls the overriding method only when signatures match.
  • Abstract method contract: the superclass declares the behavioral contract that the subclass must implement identically.
  • Return path yielding 4: the subclass implementation returns 4 when it is actually selected at runtime.
  • Vendor hint on reference type: discussion notes the reference is Automobile while the object is Car.

Why A is correct

The Car wheels method declares a parameter that the Automobile wheels declaration does not have, so the two methods are unrelated by overriding and the superclass version runs instead of the subclass version that would return 4. Removing the parameter from the subclass method, as settled key A directs, makes the signatures match, establishes a valid override of the abstract contract, and lets dynamic dispatch select the Car implementation. The program then prints 4 through the Automobile reference to the Car object.

Why the others are wrong

  • B. Removing abstract from the superclass does not fix the signature mismatch and breaks the intended abstraction.
  • C. Replacing the instantiation line does not change method resolution and leaves the overload in place.
  • D. Adding Override alone does not fix the parameter mismatch and would itself fail compilation.

1z0-819 exam tip

Same name is not enough, parameters must match exactly or it is an overload.

7Which module is required for any application using Swing or AWT?
  • java.desktop
  • java.prefs
  • java.se
  • java.logging
  • java.rmi
Answer: A

The short version

A — java dot desktop bundles Swing and AWT for modular apps. Since Java 9 modularization, UI toolkits live in a dedicated module rather than the base module. Any app using Swing or AWT must require that desktop module.

Key concepts in this question

  • Java Platform Module System: JDK libraries are partitioned into modules with explicit dependencies.
  • java dot desktop scope: this module contains java dot awt, javax dot swing, image I-O, printing, and related UI APIs.
  • Requires directive: modular apps declare dependence so the runtime resolves UI packages.
  • Other modules scope: prefs, logging, RMI, and java dot se aggregator do not themselves provide Swing or AWT.
  • Vendor confirmation: discussion explicitly identifies the desktop module as the UI carrier.

Why A is correct

Swing classes under javax dot swing and AWT classes under java dot awt are both housed in the java dot desktop module defined by the platform modularization. A modular application that touches either toolkit fails to resolve those packages unless it declares a dependence on java dot desktop. Settled key A therefore names the only module that supplies both toolkits together, while the other listed modules cover unrelated concerns.

Why the others are wrong

  • B. java dot prefs supplies preferences storage, not UI toolkit classes.
  • C. java dot se is an aggregator concept rather than the concrete module that exports Swing and AWT.
  • D. java dot logging supplies logging APIs, with no Swing or AWT packages.
  • E. java dot rmi supplies remote invocation, unrelated to desktop UI rendering.

1z0-819 exam tip

See Swing or AWT, answer java dot desktop, no other module exports those packages.

8Which set of commands is necessary to create and run a custom runtime image from Java source files?
  • java,jdeps
  • javac,jlink
  • javac,jar
  • jar,jlink
Answer: B

The short version

B — Compile with javac then link with jlink for a custom image. Source files must first become classes and modules, then the linker trims the JDK to the needed modules. That two-tool chain is the only listed pair that both compiles and links.

Key concepts in this question

  • javac role: compiles dot java sources into classes and modular descriptors for later linking.
  • jlink role: assembles a custom runtime image containing only required modules plus app modules.
  • jdeps advisory role: analyzes dependencies but does not compile or link an image.
  • jar packaging role: archives classes without creating a trimmed runtime.
  • java launch role: runs an already built image rather than building one.

Why B is correct

Creating a custom runtime image from sources requires two distinct build steps in order. First javac compiles the Java sources into class files and validates module descriptors, producing the inputs the linker needs. Then jlink resolves the module graph from those compiled modules and generates the trimmed runtime image that can launch with its own java launcher. Settled key B names exactly that compile-then-link pair, as vendor prose confirms.

Why the others are wrong

  • A. Pairs the launcher with the dependency analyzer, neither of which compiles sources into modules.
  • C. Pairs the compiler with the archiver, which packages but never links a custom runtime image.
  • D. Pairs the archiver with the linker, omitting the compilation step from sources.

1z0-819 exam tip

From sources to image remember compile then link, javac plus jlink.

9Given the code fragment: Which would cause s to be AQCD?
Java SE 11 Developer (1Z0-819) question 9
  • s.replace(s.indexOf("B"), s.indexOf("B"), "Q");
  • s.replace(s.indexOf("A"), s.indexOf("B"), "Q");
  • s.replace(s.indexOf("B"), s.indexOf("C"), "Q");
  • s.replace(s.indexOf("A"), s.indexOf("C"), "Q");
Answer: C

The short version

C — Replace the B-to-C span with Q to yield AQCD. StringBuilder replace uses start-inclusive and end-exclusive indices, so spanning from B to C replaces exactly the B character. That single-character swap turns the starting ABCD shape into AQCD.

Key concepts in this question

  • StringBuilder replace contract: replace of start and end plus string swaps the half-open range.
  • indexOf positions: indexOf of A, B, and C locates the integer offsets that bound the swap.
  • Half-open interval: end index is exclusive, so end at C leaves C in place while removing B.
  • Single-character result: replacing one character with Q preserves length and neighboring letters.
  • Tested outcome: vendor note records tested confirmation for the C variant.

Why C is correct

The builder initially holds the ABCD sequence, where indexOf of B gives the start offset and indexOf of C gives the exclusive end offset. Calling replace with those bounds and the string Q, as settled key C does, removes exactly the character at the B position and inserts Q in its place. The leading A and trailing CD remain untouched, producing AQCD in one operation.

Why the others are wrong

  • A. Uses the same index for start and end, which inserts rather than replaces and does not yield AQCD.
  • B. Spans from A to B, which would disturb the leading A instead of targeting B.
  • D. Spans from A to C, which removes two characters and cannot leave AQCD.

1z0-819 exam tip

Replace end is exclusive, span B to C to swap only B.

10Given: Which two methods facilitate valid ways to read instance fields? (Choose two.)
Java SE 11 Developer (1Z0-819) question 10
  • getCCount
  • getTCount
  • getACount
  • getGCount
  • getTotalCount
Answer: B, C

The short version

BC — Instance-field readers must run through an instance path. The fragment exposes counters where some getters are static and others reach instance state. Only the two methods that correctly dereference instance fields qualify as valid instance-field readers.

Key concepts in this question

  • Static vs instance context: static methods cannot directly read instance fields without an object reference.
  • Getter method roles: each get method targets a specific counter, but only some follow an instance path.
  • Valid reader definition: a valid instance-field reader executes in or through an instance to reach the field.
  • Bank key stability: the settled pair BC is retained as the authoritative key for this row.
  • Distractor getters: remaining getters either run statically or aggregate without directly reading the field.

Why BC is correct

The class declares instance counters alongside static helpers, so a method qualifies only when its body reaches the instance field through this or an explicit object reference. Settled keys B for getTCount and C for getACount each follow such an instance path and legally return the corresponding field value. They therefore satisfy the valid-ways-to-read-instance-fields requirement together, while the other getters do not meet the instance-access condition.

Why the others are wrong

  • A. getCCount runs through a static or otherwise non-instance path and does not qualify as an instance reader.
  • D. getGCount does not dereference the instance field through a valid instance route.
  • E. getTotalCount aggregates or runs statically rather than directly reading the target instance field.

1z0-819 exam tip

Static cannot read instance directly, look for this or an object dereference.

Want the full bank of 237 questions for Java SE 11 Developer (1Z0-819)? See all practice exams.