Reading user input in Java – simple example

There are basically 2 broad ways to read user input.

  1. Via console Input
    1. Using standard I/0 stream class
    2. Using Scanner class of utility package
    3. Using command line arguments
  2. Via user interface(GUI)
    1. Using JOptionPane(i.e input dialogbox)
    2. Using UI control(Textbox)


1. Reading through console input – I/O stream class  ( This method is not usually used nowadays)

 Using BufferedReader class

2. Using Scanner class of the utility package

3. Using Command Line Arguments

Command line arguments are used to pass the arguments during the run time of Java file. The arguments is passed from the console which can be received inside the java program and used as an input


to run:




Leave a Comment

Your email address will not be published. Required fields are marked *