Javatpoint Logo
Javatpoint Logo

Java Console readPassword() Method

The readPassword() method of Java Console class reads a password or passphrase from the console with echoing disabled.

Syntax

Parameters

N/A (not applicable, not available)

Return value:

This method returns a character array which contains the password read from the console. It does not include the line termination character. If an end of the stream has been reached, this method will return null.

Exception:

IOError: If an I/O error occurs.

Example 1

Output:

Enter the password: @javatpoint
Password is: @javatpoint 

Example 2

Output:

Enter the password: Rahul
Your name is: Rahul
Enter the password: rahul123
Your Password is: rahul123

Java Console readPassword(String fmt, Object args) Method

The readPassword(String fmt, Object args) method of Console class provides a formatted prompt, then reads a password from the console. The program can read user input from the command line without showing what the user is typing.

Syntax

Parameters

fmt: A format string as described in Format string syntax for the prompt text.

args: Arguments referenced by the format specifiers in the format string.

Return value:

This method returns a character array which contains the password read from the console. It does not include the line termination character. If an end of the stream has been reached, this method will return null.

Exception:

IllegalFormatException: If given the format string is incompatible and insufficient arguments.

Example 1

Output:

Your Name: Jony
Name is: Jony
Show password, please Enter Press:
Password is:
[C@1909752

Example 2

Output:

Your Name: Rahul
Name is: Rahul
Show old password, please Enter Press:
Password is:
 [C@1909752
Update password: rahul1234
New Password is: rahul1234
Next TopicJava Console Class





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA