Scanner class is used to read data from passed InputStream. Here it is explained how to read input by using java.util.Scanner. Below example to read user credentials by using Scanner class utility.
Example: Scanner.class
import java.util.Scanner;
class Solution {
public static void main(String args[])throws Exception{
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the username");
String username = scanner.nextLine();
System.out.println("Username: "+username);
}
}