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

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

Dive into the depths of Java with our quiz based on "Thinking in Java, Fourth Edition" by Bruce Eckel. Test your knowledge, solidify concepts, and prepare for certification with challenging questions and insightful feedback.

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.


In which scenario would you use ByteArrayInputStream?

  1. When reading from a database

  2. When working with files

  3. When reading from a memory area

  4. When downloading data from the internet

The correct answer is: When reading from a memory area

When working with files (B), you would typically use FileInputStream instead, as it is optimized for reading bytes from a file. Similarily, when reading from a database (A), you would use a JDBC query to retrieve data, not ByteArrayInputStream. When downloading data from the internet (D), you would likely use an InputStream from URL or a similar mechanism designed for remote retrieval, not ByteArrayInputStream. Therefore, the only scenario where you would truly use ByteArrayInputStream is when you need to read from a memory area (C) such as a byte array. This can be useful when dealing with packets of data in network programming or when working with large arrays of binary data in memory.