Home > DeveloperSection > Articles > Java Console Class

Java Console Class

Java Java  J2EE 
0 Comment(s)
 1234  View(s)
Rate this:

How many ways to reading data from keyboard in java

If you want to read password using Console class, it will not be displayed to the user end.

The Console class is internally attached with system console. Console class is defined in java.io package.

Let’s we take example to read user name and password given by the user end.

import java.io.*;  
class ConsoleClassEx{  
public static void main(String args[]){  
Console c=System.console();
System.out.println("Enter your name: ");  
String n=c.readLine();  
System.out.println("Enter password: ");  
char[] ch=c.readPassword(); //It's not shown  user end
String pass=String.valueOf(ch);//converting char array into string  
System.out.println("Welcome "+n); 
System.out.println("Password is: "+pass);  
}  }   

Don't want to miss updates? Please click the below button!

Follow MindStick