Mastering Java: The Ultimate Quiz for 'Thinking in Java'

Disable ads (and more) with a membership for a one time $2.99 payment

Prepare for your Java exam with our ultimate quiz based on 'Thinking in Java'. Engage with expertly crafted questions that enhance your learning process. Perfect for Java enthusiasts looking to solidify their knowledge!

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


What exception is thrown if you call 'array()' on a buffer not backed by an array?

  1. UnsupportedOperationException

  2. BufferUnderflowException

  3. BufferOverflowException

  4. ReadOnlyBufferException

The correct answer is: UnsupportedOperationException

The exception overloaded is UnsupportedOperationException. Generally excess capacity in the buffer, when calling array function which convert to an array, it will throw UnsupportedOperationException, as there is no array in the ByteBuffer. The other options, BufferUnderflowException, BufferOverflowException, and ReadOnlyBufferException, are all thrown when there is an issue with the buffer's position, limit, or read/write permissions, respectively. These are not applicable in this scenario as the issue is with the buffer not having an underlying array. Therefore, these options can be ruled out as the correct answer.