SCJP Certification

Sun Certified Java Programmer Certification exam essentials

October 29th, 2009

Which class is used to provide methods for reading and writing console objects?

Java Facts, by Daisy Williams.

The Console class is used to provide methods to read from and write to the console objects. It extends the Object class. It provides the readPassword() method to read a password from the console. If the underlying virtual machine has a console, it can be obtained by invoking the System.console() method. If no console device is available, then an invocation of the System.console() method returns null.

The Console class provides the following methods:



Method NameDescription
Console format(String str, Object… args) It writes a formatted string to this console’s output stream using the specified format string and arguments.
void flush()It flushes the console and forces any buffered output to be written immediately.
PrintWriter writer() It retrieves the unique PrintWriter object associated with this console.
Console printf(String format, Object… args) It writes a formatted string to this console’s output stream using the specified format string and arguments.
Reader reader() It retrieves the unique Reader object associated with this console.
String readLine() It reads a single line of text from the console.
String readLine(String str, Object… args) It provides a formatted prompt, then reads a single line of text from the console.
char[] readPassword() It reads a password or passphrase from the console with echoing disabled.
char[] readPassword(String str, Object… args) It provides a formatted prompt, then reads a password or passphrase from the console with echoing disabled.

Share

Back Top

Responses to “Which class is used to provide methods for reading and writing console objects?”

Comments (0) Trackbacks (0) Leave a comment Trackback url
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Your email address will not be published. Required fields are marked *

*