J2EEOnline J2EE 

Java Streams   «Prev  Next»
Lesson 2 Java Streams Course Prerequisites
ObjectiveExplore what you need to know to succeed in this course.
To successfully complete this course, you should be comfortable with :
  1. Know basic Java syntax including arrays, strings, and primitive data types
  2. Understand how Java deals with integer and byte data as well as with arrays of these data types
  3. classes, objects, and methods, particularly constructors and toString() methods
  4. Be able to write character-mode Java applications with main() methods

This course covers the Java platform classes used for basic I/O. It first focuses on I/O Streams, a powerful concept that greatly simplifies I/O operations. The course also looks at serialization, which lets a program write whole objects out to streams and read them back again. Then the course looks at file I/O and file system operations, including random access files.
Most of the classes covered in the I/O Streams section are in the java.io package. Most of the classes covered in the File I/O section are in the java.io.file package.

Identify correct statements about java.io.Console class?
  1. You can read character data from a console but not write to it.
  2. You can read both binary and character data from Console object but you cannot write to it.
  3. You can read both binary and character data from Console object but you can only write character data to it.
  4. You can read as well as write only character data from/to it.

Answer: d
Console is meant to interact with the user typically through the command/shell window and keyboard. Thus, binary data does not make sense for the console. You can read whatever the user types using readLine() and readPassword() method. You can also acquire a Reader object using reader() method on Console object. All these provide character data. Similarly, you can acquire PrintWriter object using writer() method on Console, which allows you to write character data to the console.