Community Q&A

1Z0-819 — frequently asked questions

Community-vetted answers to 32 common questions about this exam, each traced back to a specific practice question.

Questions from real practice questions

Each Q&A comes from a specific question — follow the link for the full analysis

Java var ArrayList Reassignment Compilation in 1Z0-819

Why does line 13 compile when using var with ArrayList?

Because var infers the full generic type ArrayList<String> for both listA and listC, making the assignment valid.

What if line 13 used ListA instead of listA?

Then it would be a compile error because ListA is an undeclared identifier, but that is a typo not present in the intended exam code.

What Output Does This Java Program Print for Manager AA?

Why does the manager field print as None instead of throwing a NullPointerException?

The toString() guards the manager reference (typically a ternary), so a null manager is rendered as the literal text "None" instead of being dereferenced.

Why isn't option D "AA Manager: None" the printed output?

The same toString() also appends the reports collection's size, and AA was created with two reports (BB and CC), so "Reports: 2" must appear in the line.

Valid BiPredicate Lambda Parameter Syntax

Why is mixing var and explicit types illegal?

Java does not allow combining type-inferred parameters (var) with explicitly typed parameters in the same lambda expression to maintain clarity and consistency.

Can I use final on some parameters but not others?

Yes, you can apply final to individual parameters, but it is often unnecessary for var-inferred parameters and can lead to confusion if not applied consistently.

How Many PreparedStatements and SQL Statements Execute in This JDBC Code?

Why is option E (three PreparedStatement objects) wrong for this JDBC code?

The PreparedStatement is prepared once and then reused with new setInt/setString parameters before each executeUpdate, so only two objects exist even though it is executed more than once.

Why is option D (memory leaks) not the answer?

No resource is abandoned: JDBC releases a Connection's Statements and ResultSets when the Connection is closed, which the shown code does, so no leak occurs.

Which Stream Method Finds an Item With count Below Zero?

Why doesn't filter(...).findAny() compile inside an if statement?

findAny() and findFirst() return Optional<Item>, not a boolean, so they cannot be used directly as an if condition; you would need to append isPresent().

When should allMatch be used instead of anyMatch on items?

allMatch returns true only if every item satisfies the predicate, so it answers a different question and is wrong when you just need to detect one item with count below zero.

What Does a for-Loop Stepping by Two Print?

Why doesn't the loop also print 11 as option C suggests?

The loop condition is tested before each pass; once the counter is no longer less than 10 the body is skipped, so 11 is never printed.

Why is option C (1 3 5 7 9 11) the most tempting distractor?

It lists the correct odd values but ignores the terminating bound, adding one iteration the loop never executes — a classic off-by-one trap.

Which BiPredicate Lambda Declaration Using var Is Valid?

Why can't var x be mixed with an explicit Integer y in the same BiPredicate lambda?

JLS 15.27.1 makes var in lambda parameters all-or-nothing: if any parameter uses var, every parameter must use var. Mixing var with Integer is a compile-time error, so option A fails.

Does a lambda whose parameters are all declared with var still need parentheses?

Yes. Any lambda parameter list that uses var, or that is implicitly typed with more than one parameter, must be enclosed in parentheses, which is why option C's bare var x, var y -> form is a syntax error.

Which return statements compile for a generic House method?

Why can't the method return new House<Animal>() when Animal is Dog's superclass?

Generic types are invariant: House<Animal> is not a subtype of House<Dog>, so the return fails to compile. Supertype substitution only works when the declared type is the wildcard House<? super Dog>.

Does the raw new House() really compile for a House<Dog> return type?

Yes. A raw constructor call is assignable to House<Dog> with just an unchecked-conversion warning, which is why the raw/diamond form is counted as one of the two correct answers.

What Is the Output of Console readLine and readPassword?

Why is Java not shown after the Input Password prompt?

Console.readPassword suppresses echo while Java is typed, so the password appears only later when String.valueOf(password) is printed.

What if the code printed the password char[] without String.valueOf?

Direct concatenation or println's Object handling would produce a hash code like [C@... instead of Java; String.valueOf(char[]) prevents that.

What Happens When You Sort a List Created with List.of()?

Why does sorting the List.of list throw UnsupportedOperationException?

List.of returns an immutable list, and List.sort() must replace elements in place; since the list cannot be modified, the JDK throws UnsupportedOperationException at runtime.

What would the output be if the flowers were in a new ArrayList instead?

Option A, [Red:75, Red:100, Yellow:50, Yellow:75], because a mutable list can actually be sorted by hue and then by value.

ArrayStoreException in Java Array Assignment

Why doesn't the compiler catch this error?

The compiler only knows values is A[]. Since C extends A, the assignment is legal at compile time. Runtime checks enforce the actual array type.

How to fix the code to avoid the exception?

Change the instantiation to new A[2] so the array can hold any subtype of A, including both B and C.

Java Interface Annotations with Default Values

Can I omit the 'value' name?

Yes, if it is the only element in the annotation.

Is 'val=' allowed?

No, you must use the exact name 'value' as defined in the interface.

Java Try-With-Resources: Effectively Final Variables in JDK 9+

Why is the variable not required to be declared final?

In JDK 9+, variables only need to be effectively final (not reassigned) rather than explicitly declared with the final keyword to be used in try-with-resources.

What changed in JDK 9 regarding try-with-resources?

JDK 9 extended the scope of resources to include effectively final variables defined outside the try statement, whereas JDK 7/8 required declaration inside the parentheses.

Defining Custom Exception in Java

Why isn't extending Throwable the correct answer?

While Throwable is the superclass, extending it directly is too broad. RuntimeException is the standard parent for unchecked exceptions that terminate programs naturally.

Does extending Exception cause termination?

No, extending Exception creates a checked exception. The compiler forces you to handle it, so it won't necessarily terminate the program if caught.

Effectively Final Variable Usage in Java Lambda Expressions

What is the difference between final and effectively final?

Final requires explicit declaration; effectively final means the compiler infers it because the value is never reassigned.

Can I modify the array object referenced by an effectively final variable?

Yes. Effectively final restricts reassignment of the reference, not modification of the object's internal state.

Java Bean Bound Property Change Notification

Does firePropertyChange send the old or new value?

It sends both via PropertyChangeEvent. However, if the listener reads the bean's field directly, it gets the new value if the field was updated first.

Why is this considered a bound property?

Because it uses PropertyChangeSupport to notify listeners of changes, allowing other components to react dynamically to state updates.