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

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

Mastering Java: The Ultimate Quiz for 'Thinking in Java'. Dive deep into Java with multiple-choice questions. Challenge yourself with quiz questions designed to test and improve your understanding of the 'Thinking in Java' book. Get ready for your exam!

Practice this question and more.


Which method swaps bytes according to endian-ness?

  1. swap()

  2. order(ByteOrder)

  3. flip()

  4. rewind()

The correct answer is: order(ByteOrder)

The order(ByteOrder) method is used to determine the byte order of a Buffer or Channel. This method checks the passed in ByteOrder object to determine whether the current buffer has the stated byte order. The rest of the choices, A) swap(), C) flip(), and D) rewind(), do not involve byte ordering and therefore are incorrect. Swap() is used to swap the two elements present at the specified positions, while flip() moves between read and write mode, and rewind() sets the value of position equal to zero.