# Free 1Z0-830 practice questions

> 10 free 1Z0-830 practice questions with the correct answer and an explanation.

Page: https://devopscodelab.com/exams/oracle-1z0-830/free-practice-questions/
Practice exams: https://devopscodelab.com/exams/oracle-1z0-830/

### Question 1 of 10

Given this code fragment:
String s = """
    Hello,\
     World
    """;
System.out.println(s.length());
What is printed?

- A. 14
- B. 18
- C. 12
- D. 13

**Answer:** D

**Explanation:** The closing delimiter sets the incidental indentation to four spaces, so the second line keeps one leading space. The backslash at the end of the first line is a line-continuation escape, so the two lines are joined without a line terminator, giving "Hello, World" followed by the final newline: 13 characters. 12 forgets the trailing newline, 14 assumes the backslash still leaves a newline, and 18 ignores the stripping of incidental whitespace.

### Question 2 of 10

Given:
static String describe(Object o) {
    return switch (o) {
        case Integer i when i > 10 -> "big";
        case Integer i -> "int";
        case String s -> "str" + s.length();
        default -> "other";
    };
}
What does System.out.println(describe(42) + describe(7) + describe("abc") + describe(3.0)); print?

- A. Compilation fails because the guarded case dominates the unguarded one
- B. bigbigstr3other
- C. intintstr3other
- D. bigintstr3other

**Answer:** D

**Explanation:** Pattern labels are tested top to bottom: 42 matches the guarded Integer case, 7 fails the guard and falls to the unguarded Integer case, "abc" matches the String case, and 3.0 (a Double) reaches default. A guarded pattern does not dominate an unguarded pattern of the same type, so ordering it first is legal; it is the reverse order that fails to compile. The other outputs ignore the guard or apply it to every Integer.

### Question 3 of 10

Given:
record Range(int lo, int hi) {
    Range {
        if (lo > hi) { int t = lo; lo = hi; hi = t; }
    }
}
What does System.out.println(new Range(5, 2)); print?

- A. Compilation fails because compact constructor parameters are final
- B. Range@ followed by a hash code, because records do not override toString
- C. Range[lo=5, hi=2]
- D. Range[lo=2, hi=5]

**Answer:** D

**Explanation:** In a compact constructor the parameters are ordinary, non-final variables, and their values at the end of the constructor body are assigned to the fields automatically, so the swap takes effect. The generated toString lists components in declaration order as Range[lo=2, hi=5]. Only the fields themselves cannot be assigned in a compact constructor, and records always get a generated toString.

### Question 4 of 10

Given:
public final class Team {
    private final List<String> members;
    public Team(List<String> members) { this.members = members; }
    public List<String> members() { return members; }
}
Callers can still change a Team's members after construction. Which change makes Team immutable?

- A. Return Collections.unmodifiableList(members) from members() but keep storing the caller's list
- B. Declare the members field volatile so every thread sees the same list contents
- C. Store List.copyOf(members) in the constructor and return that field from members()
- D. Make the constructor private and add a static factory method that takes the same list

**Answer:** C

**Explanation:** The caller keeps a reference to the list passed in, so a defensive copy is needed on the way in; List.copyOf creates an unmodifiable copy that can also be returned safely. An unmodifiable view returned from the accessor still reflects changes the original caller makes to its own list. volatile only affects visibility, and a factory method that stores the same list has the same flaw.

### Question 5 of 10

Given:
static int depth = 0;
static void recurse() { depth++; recurse(); }
and in main:
try {
    recurse();
} catch (Exception e) {
    System.out.println("exception");
} catch (Error e) {
    System.out.println("error " + (depth > 0));
}
What is printed?

- A. exception
- B. error true
- C. error false
- D. Nothing, because a StackOverflowError can never be caught

**Answer:** B

**Explanation:** Unbounded recursion eventually throws StackOverflowError, which is a subclass of Error, not Exception, so the first catch clause does not match. Errors can be caught like any Throwable, although recovering is usually unwise; after the stack unwinds there is room to print. depth was incremented on every call, so it is greater than zero.

### Question 6 of 10

Given (Java 21):
var set = new LinkedHashSet<>(List.of("b", "c"));
set.addFirst("a");
set.addLast("b");
System.out.println(set + " " + set.reversed().getFirst());
What is printed?

- A. [a, c, b] b
- B. An UnsupportedOperationException is thrown by addFirst
- C. [a, b, c, b] b
- D. [a, b, c] c

**Answer:** A

**Explanation:** LinkedHashSet implements SequencedSet in Java 21. addFirst and addLast insert the element at the requested end, and if it is already present they relocate it there, so b moves to the end and the set becomes [a, c, b]. A set never holds duplicates, and reversed() returns a reverse-ordered view whose first element is b. Only unmodifiable or sorted sequenced collections reject addFirst.

### Question 7 of 10

Given:
Stream.of("a", "b", "c", "d")
      .peek(System.out::print)
      .map(String::toUpperCase)
      .limit(2)
      .forEach(System.out::print);
What is printed?

- A. aAbBcCdD
- B. abcdAB
- C. aAbB
- D. abAB

**Answer:** C

**Explanation:** Streams are lazy and process one element at a time through the whole pipeline, so each element is peeked and then printed in upper case before the next one is pulled. limit(2) is a short-circuiting operation, so after two elements no more are pulled and c and d are never peeked. Printing all peeks first would require a stateful barrier such as sorted().

### Question 8 of 10

The JAR file commons-text-1.10.0.jar has no module-info.class and its manifest has no Automatic-Module-Name attribute. When the JAR is placed on the module path, which name must other modules use to require it?

- A. commons.text
- B. commons
- C. None, because a JAR without a module descriptor cannot be required by name
- D. commons.text.1.10.0

**Answer:** A

**Explanation:** A JAR on the module path without a descriptor becomes an automatic module. Without an Automatic-Module-Name attribute its name is derived from the file name: the .jar extension and the trailing version are dropped and non-alphanumeric separators become dots, giving commons.text. The version is never part of the name, the whole stem is kept rather than only its first part, and automatic modules can be required like any named module.

### Question 9 of 10

Given:
class Counter {
    private static int total;
    private int mine;
    static synchronized void addTotal() { total++; }
    synchronized void addMine() { mine++; }
}
Thread T1 is currently executing Counter.addTotal(). Thread T2 calls addMine() on a Counter instance c. Which statement is true?

- A. T2 can run addMine() at the same time, because the two methods lock different monitors
- B. T2 blocks until T1 leaves addTotal(), because all synchronized methods of a class share one lock
- C. The code fails to compile because a class cannot mix static and instance synchronized methods
- D. T2 blocks only if c was the instance most recently used by T1

**Answer:** A

**Explanation:** A static synchronized method locks the Class object (Counter.class), whereas an instance synchronized method locks the instance it is called on. Because the monitors are different, the two methods do not exclude each other. Mixing both kinds in one class is legal; to protect shared static state from instance methods, they must synchronize on the same lock explicitly.

### Question 10 of 10

Given:
Path p = Path.of("/var/log/app/server.log");
System.out.println(p.startsWith("/var/log") + " " + p.startsWith("/var/lo") + " "
                   + p.endsWith("server.log") + " " + p.endsWith(".log") + " " + p.subpath(1, 3));
On a Unix-like file system, what is printed?

- A. true false true false var/log
- B. true false true false log/app
- C. true false true true log/app
- D. true true true true log/app

**Answer:** B

**Explanation:** Path.startsWith and endsWith compare whole name elements, not characters, so "/var/lo" and ".log" do not match even though the string would. subpath(1, 3) uses zero-based name indexes, excluding the root: index 1 is log and index 2 is app, and the result is a relative path.

Ready for a timed run? Take the free 15-question 1Z0-830 mini exam: https://devopscodelab.com/app/exams/oracle-1z0-830/mini/

DevOpsCode Lab is not affiliated with Oracle. 1Z0-830 and related names are trademarks of their owners. We write every question ourselves; these are not real exam questions.
