Is there a way to mask the password from java user input that comes from Scanner class and System.out.Println()?

0 votes
I know it can be done in JPassworddField but I only want to run my program in cmd without any popup window Thanks!
May 27 in Java by Drin
1,406 views

1 answer to this question.

+1 vote

You can use the console class to do so. Refer to the example below:

import java.io.Console;
...
...
...
Console console = System.console();
char[] password = console.readPassword("Enter password");  
answered May 27 by Omkar
• 68,180 points

Related Questions In Java

0 votes
1 answer

What is the simplest way to read JSON from a URL in java

Read json from url use url.openStream() and read contents ...READ MORE

answered Jun 13, 2018 in Java by samarth295
• 2,190 points
452 views
0 votes
2 answers

What is the easiest way to iterate through the characters of a string in Java?

There are two approaches to this: for(int i ...READ MORE

answered Aug 19 in Java by Sirajul
• 40,980 points
95 views
0 votes
1 answer

Which is the standard concise way to copy a file in Java?

As toolkit mentions above, Apache Commons IO ...READ MORE

answered Nov 15, 2018 in Java by Frankie
• 9,810 points
32 views
0 votes
1 answer

Is there a way to instantiate abstract class ?

No, you are not creating the instance ...READ MORE

answered Dec 12, 2018 in Java by Sushmita
• 6,880 points
457 views
+1 vote
3 answers

What is the syntax to declare and initialize an array in java?

You can use this method: String[] strs = ...READ MORE

answered Jul 25, 2018 in Java by samarth295
• 2,190 points
686 views
0 votes
1 answer

Is it possible to run a java program from command line on windows?How?

  Let's say your file is in C:\myprogram\ Run ...READ MORE

answered Apr 18, 2018 in Java by sophia
• 1,400 points
203 views
0 votes
3 answers

How to read input from Console using Scanner Class?

A simple example: import java.util.Scanner; public class Expl { ...READ MORE

answered Jul 31, 2018 in Java by samarth295
• 2,190 points
439 views
0 votes
2 answers

What's the best way to check if a String represents an integer in Java?

You can also use regular expression. str.matches("-?\\d+"); It will ...READ MORE

answered Aug 9, 2018 in Java by Daisy
• 8,050 points
251 views
0 votes
1 answer

Unable to Run the .java file

You have to enter the commands as ...READ MORE

answered Jan 10 in Java by Omkar
• 68,180 points
52 views
0 votes
2 answers

What is the meaning of purpose of this command: java -jar <some jar file>.jar ?

JAR (Java Archive) file is a package file ...READ MORE

answered Mar 21 in Java by Omkar
• 68,180 points
58 views