The following illustrates reading password in console in Java which means that password isn't visible when the user is typing.
System.console().readPassword(): The console() method generates a Console object which contains the readPassword() method. This method reads the password from the user into a char array and returns it.class ReadPassword
{
public static void main(String args[])
{
System.out.println("Enter password");
char[] c=System.console().readPassword();
// Just print, make it simple
System.out.println("The password is "+new String(c));
}
}