If you are using AWT or Swing you can use the following Echoing Character specifier as below respectively:
AWT
Code:
TextField pwd = new TextField(someInt);
pwd.setEchoChar('*');
Swing
Code:
JPasswordField pwd = new JPasswordField(someInt);
pwd.setEchoChar('*');
For command line, its sort of difficult I guess cause you need to use the
Console class.
An example would be like thus:
Code:
import java.io.Console;
public class Password
{
public static void main (String args[])
{
Console c = System.console();
String id = c.readLine("ID: ");
char [] pass = c.readPassword("Pass: ");
}
}
On UNIX consoles like mine it doesn't echo anything, I don't know about Windows, must show an asterix though.
Remember that
readPassword method of Console returns a
char [] and not String.
Umm, redhat deleted your post? I was gonna flame! Come back!