
Reading User's Input using Console classThe Console class was introduced in Java 1.6, and it has been becoming a preferred way for reading user’s input from the command line. Learn more: Java Scanner Tutorial and Code Examples 3. The reading methods are not synchronized.Regular expressions can be used to find tokens.Convenient methods for parsing primitives ( nextInt(), nextFloat(), …) from the tokenized input.Here’s an example: Scanner scanner = new Scanner(System.in) Reading User's Input using Scanner classThe main purpose of the Scanner class (available since Java 1.5) is to parse primitive types and strings using regular expressions, however it is also can be used to read input from the user in the command line. Drawbacks: The wrapping code is hard to remember.

Advantages: The input is buffered for efficient reading. ("Your name is: " + name) In the above example, the readLine() method reads a line of text from the command line. Here’s an example: BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))

Reading User's Input using BufferedReader classBy wrapping the System.in (standard input stream) in an InputStreamReader which is wrapped in a BufferedReader, we can read input from the user in the command line. Each way is fairly easy to use and also has its own advantages and drawbacks. In this article, we discuss three different ways for reading input from the user in the command line environment (also known as the “console”).
