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, 2019 in Java by Drin
11,135 views

1 answer to this question.

0 votes

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, 2019 by Omkar
• 69,220 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,220 points
5,203 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, 2019 in Java by Sirajul
• 59,230 points
1,879 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,830 points
670 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,920 points
8,712 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,220 points
3,623 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
2,721 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 Aug 1, 2018 in Java by samarth295
• 2,220 points
5,262 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,140 points
3,988 views
0 votes
1 answer

Unable to Run the .java file

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

answered Jan 11, 2019 in Java by Omkar
• 69,220 points
806 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 22, 2019 in Java by Omkar
• 69,220 points
2,671 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP