Masking a password with the Console class
import java.io.Console; public class Main { public static void main(String[] args) { Console console = System.console(); char passwordArray[] = console.readPassword("Enter your secret password: "); console.printf("Password entered was: %s%n", new String(passwordArray)); } }