Alright, let's elaborate with some simplified explanation about the Scanner class.

It is a standard Oracle class which you can use by calling the import java.util.Scanner.

So let's make a basic example of the class:

class Scanner {
   InputStream source;

   Scanner(InputStream src) {
       this.source = src;
   }

   int nextInt() {
       int nextInteger;
       //Scans the next token of the input as an int from the source.
       return nextInteger;
   }
}

Now when you call Scanner input = new Scanner(System.in); you make a new object of the Scanner class (so you make a new "Scanner") and you store it in the variable input. At the same time you are calling the (so called) constructor of the class, with the parameter System.in. That means it is going to read from the standard input stream of the program.

Now when you are calling input.nextInt(); you execute the method from the object you just created (also documented). But as we see, this method returns a integer, so if we want to use that integer, we have to assign the call to a variable like you do:

int i = input.nextInt();
Answer from moffeltje on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › java › scanner-class-in-java
Scanner Class in Java - GeeksforGeeks
Scanner sc = new Scanner (System.in); Here "sc" is an object of the Scanner class. We can give it different names for our ease such as in, var or obj etc. Using this object we can use the methods of the Scanner class. int age = sc.nextInt(); ...
Published   May 27, 2026
Discussions

java - Scanner sc = new Scanner(System.in) - Resource Leak? - Stack Overflow
Lifetime is entire main() method, ... System.in. ... I have updated the code from a link. Sorry! ... You need to close() the scanner so that any resources held by it can be released. Ideally, this is done in a finally block so that you are sure that you will always release the resources accumulated by the scanner. Thus, you would need to declare the scanner: Scanner sc = null, then, ... More on stackoverflow.com
🌐 stackoverflow.com
Scanner input = new Scanner(System.in);
Let's break it down. The line is Scanner input = new Scanner(System.in); Let's break the down. We can split this into two statements: Scanner input; input = new Scanner(System.in); You understand this split? The first line is the same as int catCounter; or String catName;, just it's Scanner instead of a string or int. The second line, well the input = [something] should be obvious enough. It's the same as catCounter = 15; or catName = "Fluffy";. This leaves only new Scanner(System.in);. Because Scanner is an class and not a primitive, you need to create one by using the keyword new and the constructor for the Scanner class. A constructor is just a special method for a class that is called when you create an object of that class. System.in just tells the scanner what to use for the input. Scanners can use different kinds of input, System.in is just the standard terminal input (like how you use System.out.println() (emphasis on the system.out part) to print to the terminal. More on reddit.com
🌐 r/learnprogramming
3
1
December 2, 2017
What exactly is Scanner??
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/javahelp
22
1
October 31, 2023
Is Scanner a Type or a Method? Why is it used with System.in?
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/javahelp
8
4
August 3, 2025
People also ask

Q5. What is the use of a Scanner?
The Scanner is used to take input from the user and make it easy to read and process numbers, text, or other data types in a program.
🌐
intellipaat.com
intellipaat.com › home › blog › scanner class in java
Scanner Class in Java: Syntax, Methods, and Examples
Q3. How to write a Scanner class?
You create a Scanner object in your program using: Scanner sc = new Scanner(System.in);
🌐
intellipaat.com
intellipaat.com › home › blog › scanner class in java
Scanner Class in Java: Syntax, Methods, and Examples
Q4. What does Scanner next() return?
The next() method returns the next word or token from the input as a String.
🌐
intellipaat.com
intellipaat.com › home › blog › scanner class in java
Scanner Class in Java: Syntax, Methods, and Examples
🌐
Sololearn
sololearn.com › en › Discuss › 1816141 › what-does-scannersystemin-mean
what does Scanner(System.in) mean? | Sololearn: Learn to code for FREE!
System.in is variable with definition about what is standard input stream. usualy it is console user keyboard input. Scanner is class for read this input stream. import java.util.Scanner; class Example { public static void main(String[] args) ...
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › Scanner.html
Scanner (Java Platform SE 8 )
April 21, 2026 - Scanner sc = new Scanner(new File("myNumbers")); while (sc.hasNextLong()) { long aLong = sc.nextLong(); } The scanner can also use delimiters other than whitespace. This example reads several items in from a string: String input = "1 fish 2 fish red fish blue fish"; Scanner s = new ...
🌐
W3Schools
w3schools.com › java › java_user_input.asp
Java User Input (Scanner class)
In our example, we will use the nextLine() method, which is used to read Strings: import java.util.Scanner; // Import the Scanner class class Main { public static void main(String[] args) { Scanner myObj = new Scanner(System.in); // Create a Scanner object System.out.println("Enter username"); String userName = myObj.nextLine(); // Read user input System.out.println("Username is: " + userName); // Output user input } }
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › docs › api › java.base › java › util › Scanner.html
Scanner (Java SE 17 & JDK 17)
April 21, 2026 - Scanner sc = new Scanner(new File("myNumbers")); while (sc.hasNextLong()) { long aLong = sc.nextLong(); } The scanner can also use delimiters other than whitespace. This example reads several items in from a string: String input = "1 fish 2 fish red fish blue fish"; Scanner s = new ...
Find elsewhere
🌐
Programiz
programiz.com › java-programming › scanner
Java Scanner (With Examples)
// read input from the input stream Scanner sc1 = new Scanner(InputStream input); // read input from files Scanner sc2 = new Scanner(File file); // read input from a string Scanner sc3 = new Scanner(String str); Here, we have created objects of the Scanner class that will read input from ...
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › util › Scanner.html
Scanner (Java Platform SE 7 )
Scanner sc = new Scanner(new File("myNumbers")); while (sc.hasNextLong()) { long aLong = sc.nextLong(); } The scanner can also use delimiters other than whitespace. This example reads several items in from a string: String input = "1 fish 2 fish red fish blue fish"; Scanner s = new ...
🌐
CodeGym
codegym.cc › java blog › java classes › java scanner class
Scanner Class in Java | CodeGym
April 1, 2025 - Scanner sc = new Scanner(System.in); System.out.println("Enter a number:"); if (sc.hasNextInt()) { int number = sc.nextInt(); System.out.println("Thanks! You entered the number " + number); } else { System.out.println("Sorry, this is not a number.
🌐
SoftTeco
softteco.com › home › java development › java scanner
Java Scanner: everything you need to know about this Java clas
June 9, 2026 - Scanner scanner = new Scanner (System.in); It helps read the input of primitive types (i.e. int, double, long, short, float, or byte) and is the easiest way to read input in Java.
🌐
LabEx
labex.io › questions › why-do-we-use-scanner-scanner-new-scanner-system-in-in-th-272885
Why do we use 'Scanner scanner = new Scanner(System.in);' in the Java program? | LabEx
February 19, 2026 - Scanner scanner = new Scanner(System.in); System.out.print("Enter your name: "); String name = scanner.nextLine(); // Reads a line of text input scanner.close(); // Closes the scanner
🌐
Runestone Academy
runestone.academy › ns › books › published › javajavajava › pg-sec-scannerclass.html
2.7 From the Java Library: java.util.Scanner
The following statement will declare and instantiate an object that can be used for keyboard input: 🔗 · Scanner sc = new Scanner(System.in); After we create a Scanner object, we can make a call to nextInt(), nextDouble(), or next(), depending on the type of input data we want — an integer, ...
🌐
DigitalOcean
digitalocean.com › community › tutorials › scanner-class-in-java
Scanner Class in Java | DigitalOcean
August 4, 2022 - Scanner sc = new Scanner(System.in); sc.useDelimiter(System.getProperty("line.separator")); System.out.println("Please enter your name"); String name = sc.next(); System.out.println("Hello " + name); sc.close(); Let’s look at a simple example to read and parse CSV files using the scanner class.
🌐
Coderanch
coderanch.com › t › 775648 › java › scanner-input
scanner input (Beginning Java forum at Coderanch)
July 30, 2023 - Billy Estes wrote:My question is I have 5 classes I want to use scanners in all of them I have tryed using scanner intact and not closing them I saw where I place my scanner in a public final Scanner in =new scanner(system.in) and use main class name.in to tha call that won't work. I get illegalmodifier for peramiter sc,only final is permitted.
🌐
Quora
quora.com › What-does-Scanner-S-new-Scanner-system-in-means-in-Java
What does Scanner S=new Scanner (system.in) means in Java? - Quora
Answer (1 of 9): Lets break it down Scanner: The Scanner class is a class in java.util, which allows the user to read values of various types System.in: An InputStream which is typically connected to keyboard input of console programs > Scanner S=new Scanner(System.in)...
🌐
Reddit
reddit.com › r/learnprogramming › scanner input = new scanner(system.in);
r/learnprogramming on Reddit: Scanner input = new Scanner(System.in);
December 2, 2017 -

can someone give me the meaning of Scanner input = new Scanner(System.in); statement , i know its used to get the user input stored in a variable ,or at least leads to

please correct me if im wrong , im still a beginner

Top answer
1 of 3
8
Let's break it down. The line is Scanner input = new Scanner(System.in); Let's break the down. We can split this into two statements: Scanner input; input = new Scanner(System.in); You understand this split? The first line is the same as int catCounter; or String catName;, just it's Scanner instead of a string or int. The second line, well the input = [something] should be obvious enough. It's the same as catCounter = 15; or catName = "Fluffy";. This leaves only new Scanner(System.in);. Because Scanner is an class and not a primitive, you need to create one by using the keyword new and the constructor for the Scanner class. A constructor is just a special method for a class that is called when you create an object of that class. System.in just tells the scanner what to use for the input. Scanners can use different kinds of input, System.in is just the standard terminal input (like how you use System.out.println() (emphasis on the system.out part) to print to the terminal.
2 of 3
2
Scanner let's you can extract the information you wan't from input, characters, lines numbers and so on. You can make multiple new Scanners if you wish. The input doesn't necessarily need to be keyboard input, it can also be a file or String. Inside the parens you place what input you want to parse. 'in', in System.in the InputStream which reads byte data from keyboard input. However you can not do; InputStream keyboard = new InputStream(); // does not work You have to use System.in [You can use System.in without a Scanner] ( https://tio.run/##RY2xTsQwEER7f8V22EUs@gg6JKiDRIGu2NhLboOzjuxNDnS6bw9GQqKaYt68mXHHLq8kc/w8jpCwVuB8Nes2Jg5QFbXFnjnCgixgBy0s0/sJsEzVgZ5LvlSYm8YnlMk/fQValbNczUculkWBH4bvqrR4Ft84Tjgmsq7nrnu87535a/Omfm1ytTacsbj/USGM1rne3MztOMatKfWuwpILQciykzC1H5QIGHcOv34wmmGr1FB4e3l9BoQhoAiVHw ) When you put System.in inside the parens of new Scanner( ) Then Scanner takes 'in' as argument to a constructor, and then that scanner let's you deal with user input more conveniently.
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › scanner class in java
Scanner Class in Java: Syntax and Methods
April 21, 2025 - You can create it using: Scanner sc = new Scanner(System.in); This allows the program to read user input from the console.
🌐
Intellipaat
intellipaat.com › home › blog › scanner class in java
Scanner Class in Java: Syntax, Methods, and Examples
December 15, 2025 - You create a Scanner object in your program using: Scanner sc = new Scanner(System.in);