import java.io.Console;
public class ConsoleTest
{
public static void main(String[] args) throws Exception
{
Console console = System.console();
if (console == null)
{
System.out.println("Unable to fetch console");
return;
}
System.out.print("Enter username:");
String user = console.readLine();
System.out.print("Enter password:");
char ch[] = console.readPassword();
String password = String.valueOf(ch);
System.out.println("Username: "+user);
System.out.println("Password:"+password);
}
}