java.util.Scanner class in Java | Java Tutorial

This  Java Tutorial”java.util.Scanner class in Java” post explaining clearly how to instantiate Scanner class and how to read different types of input from the keyboard using Scanner class.


Scanner class:

  • Scanner class available in “java.util” package.
  • Scanner class since JDK 1.5
  • In C-language, we can read the input from the end-user using scanf( ) function.
  • In java, using different classes we can collect input from End-user.
  • Scanner class can capable of reading information from different input sources like keyboard, File, Socket etc.
  • We need to “import” Scanner class while using in the java application.


  • While constructing Scanner class Object, we need to specify Input source.


  • How to provide KEYBOARD input source to Scanner class Object?


Note : Scanner class is having number of pre-defined non-static methods to read different kinds of input from End-user.


Program that reads int and float values using Scanner class :


Share this