10 free Oracle 1Z0-819 practice questions with the correct answer and a full explanation for each, taken from the CertStash pack of 213 questions. Work through them, then open each answer to check your reasoning.
Get all 213 questions (US$39) · Download these 10 as a PDF
Question 1
Given:
What is the result?

Show answer and explanation
Correct answer: C. 1-5
The loop initializes x=0, y=6 and continues while x < y, incrementing x and decrementing y each iteration. On each iteration, if x is even (x%2 == 0), the continue statement skips the print statement and moves to the next iteration. When x is odd, the print statement executes. Iteration 1: x=0 (even, skipped), y=5; Iteration 2: x=1 (odd, prints "1-5"), y=4; Iteration 3: x=2 (even, skipped), y=3; Iteration 4: x=3 (odd, prints "3-3"), y=2; Loop terminates when x=4, y=1 (x < y is false). Wait, recalculating: At iteration where x=3, y=2, we have x < y (3 < 2 is false), so the loop ends after x=2, y=3. So: x=0 skipped, x=1 prints "1-5", x=2 skipped, then x=3, y=2 fails the condition. Therefore only "1-5" prints.
Why the other options are wrong
- A. Missing the output from when x=1; the loop produces one output line, not just the final state.
- B. Includes x=0 and x=2 outputs, but these are skipped by the continue statement since they are even numbers.
- D. Includes x=2, but x=2 is even and triggers continue, preventing any output for that iteration.
- E. The code compiles without error; line 1 is syntactically valid.
- F. Represents only the initial state; x=0 is skipped by continue since 0%2==0.
- G. Includes x=0 and x=2, both of which are skipped by the continue statement for even numbers.
Question 2
Given:
What is the result?

Show answer and explanation
Correct answer: D. 5 4 3 2 1 4 3 2 1 3 2 1 2 1 1
The code executes a do-while loop that continues while i > 0. In each iteration, the for loop prints values from i/2 down to 1, then i is decremented by 2. Starting with i=10: the for loop prints 5 4 3 2 1 (from 10/2=5 down to 1), then i becomes 8. Next iteration prints 4 3 2 1 (from 8/2=4 down to 1), then i becomes 6. Next iteration prints 3 2 1 (from 6/2=3 down to 1), then i becomes 4. Next iteration prints 2 1 (from 4/2=2 down to 1), then i becomes 2. Final iteration prints 1 (from 2/2=1 down to 1), then i becomes 0 and the loop exits. The complete output is: 5 4 3 2 1 4 3 2 1 3 2 1 2 1 1.
Why the other options are wrong
- A. This only shows the first iteration's output and misses the subsequent iterations of the do-while loop.
- B. This shows only a single value and ignores the for loop that prints multiple decreasing values in each iteration.
- C. Nothing is printed only if the code doesn't execute, but the do-while loop's condition is checked after execution, ensuring at least one iteration runs.
Question 3
Given:
and
Which two method definitions at line n1 in the Bar class compile? (Choose two.)

Show answer and explanation
Correct answer: B, C
B. public List<Integer> foo(Set<CharSequence> m) {…} C. public List<Integer> foo(TreeSet<String> m) {…} When Bar extends Foo, it can override the foo method with a covariant return type, which must be a subtype of the parent's return type (List<Integer>). Option B uses List<Integer> with Set<CharSequence>, which is valid because CharSequence is a supertype of String, making the parameter contravariant-compatible. Option C uses TreeSet<String>, which is a subtype of Set<String>, and ArrayList<Integer> is a subtype of List<Integer>, satisfying covariance rules. Option A fails because Number is not a subtype of Integer. Option D fails because Object is not a subtype of Integer. Option E fails because the parameter must be Set<String> or a supertype thereof, not a more specific implementation. Option F fails because Number is not a subtype of Integer for the return type.
Why the other options are wrong
- A. Number is not a subtype of Integer, violating covariant return type rules.
- D. Object is not a subtype of Integer, violating covariant return type rules.
- E. TreeSet is a more specific type than Set, which violates contravariance for method parameters during override.
- F. Number is not a subtype of Integer, failing covariant return type requirements.
Question 4
Given:
What is the result?

Show answer and explanation
Correct answer: B. 4
Starting with a StringBuilder of capacity 5, the operations execute sequentially: append("HOWDY") produces "HOWDY"; insert(0, ' ') produces " HOWDY"; replace(3, 5, "LL") replaces characters at indices 3-4 ("WD") with "LL" producing " HOWLL"; insert(6, "COW") inserts "COW" at index 6 producing " HOWLLCOW"; delete(2, 7) removes characters at indices 2-6 ("WLLC") producing " OOW"; finally length() returns 4.
Why the other options are wrong
- A. The final length is not 5; the delete operation removes 5 characters, reducing the string from 9 to 4 characters.
- C. After all operations complete, the StringBuilder contains 4 characters, not 3.
- D. No exception is thrown; all operations are valid on the StringBuilder object with sufficient capacity.
Question 5
Given the code fragment:
What is the result?

Show answer and explanation
Correct answer: E. 0 8
The loop runs from i=0 to i<10. On each iteration, i is evaluated with switch(i % 5). When i=0, 0%5=0, which matches no case, so default executes and breaks. The print outputs 0 and i increments to 1. When i=1 through i=4, none match cases 1-4 (case 1 and 4 lack breaks and fall through to continue), so they skip to the next iteration. When i=5, 5%5=0, which again matches no case, so default executes and breaks, printing 5. However, examining the case statements more carefully: case 2 executes i*=2*i (modifying i), case 3 executes i++, cases 1 and 4 fall through to continue (skipping the print), and default breaks. Tracing: i=0 (0%5=0)→default→print 0, i=1 (1%5=1)→case 1→continue, i=2 (2%5=2)→i*=2*2=8→break→print 8, i=9 (9%5=4)→case 4→i++→continue, i=10 (exits loop). The output is 0 8.
Why the other options are wrong
- A. This includes 10, but the loop condition i<10 prevents i from reaching 10 before the loop terminates.
- B. This only includes 0, missing the case 2 execution where i is reassigned to 8 and printed.
- C. The code does produce output; it prints values from the System.out.print statements inside the loop.
- D. The value 4 never appears in output; case 2 multiplies i by itself, and case 3 increments but falls through to continue without printing.
Question 6
Given the code fragment:
You want to display the value of currency as $100.00.
Which code inserted on line 1 will accomplish this?

Show answer and explanation
Correct answer: D. NumberFormat formatter = NumberFormat.getCurrencyInstance(locale);
NumberFormat.getCurrencyInstance(locale); To display a number as currency in the specified locale, you need to use NumberFormat.getCurrencyInstance(locale), which returns a NumberFormat object specifically configured for currency formatting. This method applies locale-specific currency symbols and formatting rules. Option D is the correct and direct method for obtaining a currency formatter for a given locale.
Why the other options are wrong
- A. getInstance() returns a general number formatter, not a currency formatter, and getCurrency() is not a valid method on NumberFormat.
- B. getCurrency() is not a static method on NumberFormat; the correct method name is getCurrencyInstance().
- C. getInstance() returns a general-purpose NumberFormat that formats numbers, not currency, so it will not display the dollar sign and proper currency formatting.
Question 7
Which three initialization statements are correct? (Choose three.)
Show answer and explanation
Correct answer: B, C, F
B. short sh = (short)’A’; C. float x = 1f; F. int x = 12_34; Option B is correct: casting a char to short is valid since both are numeric types. Option C is correct: the 'f' suffix explicitly declares a float literal. Option F is correct: underscores in numeric literals are allowed for readability (12_34 = 1234). Option A fails because a 3D array cannot be initialized with 2D array literals of mismatched dimensions. Option D fails because assigning a byte to char requires explicit casting (chars are unsigned 16-bit, bytes are signed 8-bit). Option E fails because the variable name 'contact#' contains an invalid character (#); only letters, digits, underscores, and dollar signs are allowed, and the name cannot start with a digit. Option G fails because 'false' is a reserved keyword and cannot be used as a variable name.
Why the other options are wrong
- A. Multidimensional array initialization dimensions do not match the declared type.
- D. Assignment of byte to char requires explicit casting due to type incompatibility.
- E. Variable name contains '#', which is not a valid identifier character.
- G. The word 'false' is a reserved keyword and cannot be used as a variable name.
Question 8
Your organization makes mlib.jar available to your cloud customers. While working on a new feature for mlib.jar, you see that the customer visible method public void enableService(String hostName, String portNumber) executes this code fragment and you see this grant is in the security policy file:
What security vulnerability does this expose to your cloud customer's code?

Show answer and explanation
Correct answer: E. denial of service attack against any reachable machine
The mlib.jar code uses AccessController.doPrivileged() to create a Socket with custome-upplied hostname and port number while operating under a broad SocketPermission grant that allows "*" (any host) connections. This allows malicious customer code to exploit the trusted library to establish socket connections to arbitrary machines on the network, including internal systems, external targets, or the customer's own infrastructure. The customer code itself may not have SocketPermission, but by invoking this public method with attacker-controlled parameters, it can leverage the library's elevated privileges to perform network reconnaissance, attack other systems, or disrupt services, a classic denial of service vector. The vulnerability is not about SQL or XML injection (which are application-layer attacks unrelated to socket permissions), nor is it mitigated by requiring the customer code to have its own SocketPermission, since the whole security bypass occurs through the privileged method itself.
Why the other options are wrong
- A. OS-level privilege escalation requires OS exploitation techniques; this vulnerability operates within the Java security model and does not escalate OS privileges.
- B. SQL injection is an application-layer database attack unrelated to raw socket communication or permission grants.
- C. XML injection is an application-layer parsing attack and is not the vulnerability exposed by unrestricted socket creation via doPrivileged().
- D. The customer code does not need SocketPermission because the vulnerability is that mlib.jar's doPrivileged() block bypasses security checks; the customer exploits this trusted code path.
Question 9
Given:
and
What is the result?

Show answer and explanation
Correct answer: A. Joe null
The main method creates a Person object p with name "Joe" and calls checkPerson(p), printing "Joe". Then p is set to null and checkPerson(p) is called again. Since p is null, the if condition (p == null) is true, so checkPerson creates a new Person("Mary") and assigns it to the local parameter p. However, this assignment only affects the local parameter inside checkPerson, it does not change the p variable in main. The method returns this local reference, but main ignores the return value. When System.out.println(p) executes, p in main is still null, printing "null". The output is "Joe" followed by "null".
Why the other options are wrong
- B. The first call prints "Joe" (not null) because p is initialized with a valid Person object before the first checkPerson call.
- C. The second output cannot be "Mary" because the new Person("Mary") created inside checkPerson is only assigned to the local parameter and is not returned to or used in main.
- D. The first output cannot be null because p is initialized as new Person("Joe") before any null assignment occurs.
Question 10
Given:
What is the result?

Show answer and explanation
Correct answer: C. [A, B, C] [A, B, C]
Line 8 creates an unmodifiable (immutable) view of list1 using Collections.unmodifiableList(). This returns a wrapper that prevents structural modifications to the underlying list. When line 9 attempts to add "C" to list1, the addition succeeds because list1 itself is still mutable, the unmodifiable wrapper (list2) does not affect the original list's mutability. Therefore, list1 becomes [A, B, C]. Line 10 prints list1 as [A, B, C]. Line 11 prints list2, which is an unmodifiable view of list1 at the time it was created (after the addition of "C"), so list2 also shows [A, B, C]. The unmodifiable list still reflects changes made to the underlying list through other references; it only prevents direct modifications through the list2 reference itself.
Why the other options are wrong
- A. Line 9 does not throw an exception because it modifies list1 directly, not through the unmodifiable wrapper list2.
- B. list2 reflects the state of list1 after line 9's addition, so it contains [A, B, C], not [A, B].
- D. Line 9 modifies list1 directly, which is still mutable; the exception would only occur if attempting to modify through list2.
That was 10 of 213.
The full Oracle 1Z0-819 pack has all 213 questions, each with the answer, the explanation and why the other options are wrong, plus a questions-only copy for timed runs. US$39, paid once, with free monthly updates and a pass-or-your-money-back guarantee.
