Core Java API Flashcards
7 cards from real 1Z0-811 practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 7 Core Java API flashcards as text
What does `Collections.unmodifiableList(list)` guarantee?
Answer: Mutations through the wrapper throw UnsupportedOperationException
The unmodifiable wrapper throws UnsupportedOperationException on mutating calls, but mutations to the backing list are still visible through the wrapper.
What is printed by `System.out.println(Integer.toBinaryString(-1))`?
Answer: "11111111111111111111111111111111"
`Integer.toBinaryString(-1)` returns the unsigned 32-bit binary representation of -1, which is 32 ones.
Which `Map` method returns the value associated with a key, or a default if the key is absent?
Answer: getOrDefault()
`Map.getOrDefault(key, defaultValue)` returns the mapped value or the specified default without modifying the map.
What is the result of `String.format("%05d", 42)`?
Answer: "00042"
The format specifier `%05d` pads the integer with leading zeros to a width of 5, producing "00042".
Which statement about `ArrayList` vs `LinkedList` is accurate?
Answer: ArrayList has O(1) random get by index
ArrayList backed by an array supports O(1) index-based access, while LinkedList requires O(n) traversal to reach an element.
What does `Math.round(2.5)` return in Java?
Answer: 3
`Math.round(2.5)` returns 3 (a long); it uses half-up rounding, so .5 always rounds toward positive infinity.
What exception is thrown when you access an index beyond the end of an array?
Answer: ArrayIndexOutOfBoundsException
Accessing an invalid array index throws `ArrayIndexOutOfBoundsException`, a subclass of IndexOutOfBoundsException.