Scanner Class in Java


This tutorial is all about Scanner Class in Java
is a concrete class in Java. Hence, we can create object of Scanner class using new operator.

Scanner sc= new Scanner (;

It is developed inside java.util package and was introduced in JDK 1.5 . It is having one constructor which required input stream through .


Let us take a simple example :

import java.util.Scanner ;

class DemoScanner{

public static void main (String[] args){

Scanner sc=new Scanner(;

System.out.println(“Enter something”);


System.out.println(“You have entered: “+s1);



next() is a method inside Scanner class , whenever this line is executed, the execution will halt there and it require some input through (keyboard )

Few other methods inside Scanner class are: nextInt() , nextBoolean() , nextDouble (), etc..



Depending on the input from the keyboard , respective method are used.

Facebook Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.