Sams Teach Yourself Java 2 in 24 Hours

Sams Teach Yourself Java 2 in 24 Hours

By Rogers Cadenhead

Questions

  1. Which of the following techniques can be used to convert an array of bytes into a string?
    1. Call the array's toString() method.
    2. Convert each byte to a character, then assign each one to an element in a String array.
    3. Call the String() constructor method with the array as an argument.
  2. What kind of stream is used to read from a file in a Java program?
    1. an input stream
    2. an output stream
    3. either
  3. What method of the File class can be used to determine the size of a file?
    1. getSize()
    2. read()
    3. length()

Answers

  1. c. You can deal with each byte individually, as suggested in answer b., but you can easily create strings from other data types.
  2. a. An input stream is created from a File object or by providing a filename to the input stream's constructor method.
  3. c. This method returns a long representing the number of bytes in the stream.

Share ThisShare This

Informit Network