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 checks the number of bytes that can be read without blocking?

  1. read

  2. available

  3. checkRead

  4. peek

The correct answer is: available

The method that checks the number of bytes that can be read without blocking is the 'available' method. This method returns an integer representing the number of bytes that can be read without blocking and therefore allows for the reading of data without interruption. Options A, C, and D are incorrect as they do not provide a function to determine the number of bytes that can be read without blocking. Option A, 'read', simply reads the data and does not provide any information about how much data can be read. Option C, 'checkRead', is not a valid method for checking the number of bytes and option D, 'peek', only allows the user to see the next byte without actually reading it. Therefore, 'available' is the only valid option for checking the number of bytes that can be read without blocking.