Scanner is a class. By using the “new” operator, you are creating an object from that class. The parentheses indicate that you are calling a method (in this case, the constructor, which is why its name is same as class. The System.in is the parameter passed to the constructor, in this case telling Scanner where it is scanning from (System.in is the keyboard). So it’s telling the Scanner object to look for input from the keyboard. Basically, this is how you can read something a user types, like answer to a yes/no question, or the number pressed from a numbered menu, etc… Answer from kingtermite on reddit.com
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › Scanner.html
Scanner (Java Platform SE 8 )
April 21, 2026 - All Classes · Summary: Nested | Field | Constr | Method · Detail: Field | Constr | Method · compact1, compact2, compact3 · java.util · java.lang.Object · java.util.Scanner · All Implemented Interfaces: Closeable, AutoCloseable, Iterator<String> public final class Scanner extends Object implements Iterator<String>, Closeable ·
🌐
W3Schools
w3schools.com › java › java_user_input.asp
Java User Input (Scanner class)
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Practice Problems Java Server Java Syllabus Java Study Plan Java Interview Q&A ... The Scanner class is used to get user input, and it is found in the ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › scanner-class-in-java
Scanner Class in Java - GeeksforGeeks
Scanner is a predefined class in Java used to take input from the user. It is present in the java.util package and supports different types of input such as integers, strings, float values, and characters.
Published   May 27, 2026
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.util.scanner
Scanner Class (Java.Util) | Microsoft Learn
A simple text scanner which can parse primitive types and strings using regular expressions.
🌐
Zero To Mastery
zerotomastery.io › blog › java-scanner
Beginner's Guide To Java Scanner (With Code Examples) | Zero To Mastery
This tells Java, "I want to use the Scanner class in this program." Without this import, trying to use Scanner would result in a compilation error.
Find elsewhere
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › Java-Scanner-User-Input-example-String-next-int-long-char
Java Scanner User Input Example
Found in the java.util package, Java’s Scanner class can read input from the command line and return it as a String, BigDecimal or any one of Java’s eight primitive types.
🌐
Medium
medium.com › buzz-code › java-8-scanner-class-660b03d4bb91
Java 8 | Scanner Class
January 18, 2021 - So with the Scanner class you can type something in from the console. First you need to create the new Scanner class and then put it in the Scanner variable.
🌐
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 - A simple text scanner which can parse primitive types and strings using regular expressions.
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › Java-String-input-with-the-Scanner-class
Java Scanner String input example
import java.util.Scanner; public class ScannerUserInput { public static void main(String[] args) { // String input with the Java Scanner System.out.println("How old are you?"); Scanner stringScanner = new Scanner(System.in); String age = ...
🌐
Baeldung
baeldung.com › home › java › java io › java scanner
Java Scanner | Baeldung
January 5, 2024 - In this quick tutorial, we’ll illustrate how to use the Java Scanner class – to read input and find and skip patterns with different delimiters.
🌐
CodeGym
codegym.cc › java blog › java classes › java scanner class
Scanner Class in Java | CodeGym
April 1, 2025 - Its functionality is very simple. Like a real scanner, it reads data from a source that you specify. For example, a string, a file, the console. Next, it recognizes the information and processes it appropriately.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-user-input-scanner-class
Java User Input - Scanner Class - GeeksforGeeks
The Scanner class, introduced in Java 5, belongs to the java.util package allows developers to read input from different sources easily.
Published   January 16, 2026
🌐
Sololearn
sololearn.com › en › Discuss › 280825 › using-the-scanner-class-in-java
Using the scanner class in Java?
Sololearn is the world's largest community of people learning to code. With over 25 programming courses, choose from thousands of topics to learn how to code, brush up your programming knowledge, upskill your technical ability, or stay informed about the latest trends.
🌐
PW Skills
pwskills.com › blog › java › java-scanner-class
Java Scanner Class - Definition And Example
The java.util package in Java has a class called Scanner. This class helps to connect the program with the input stream, allowing it to read and understand different types of data like strings, characters, integers, and doubles.
🌐
Tutorialspoint
tutorialspoint.com › java › java_util_scanner.htm
Java - Util Scanner Class
The Java Scanner class is a simple text scanner which can parse primitive types and strings using regular expressions.Following are the important points about Scanner − Following is the declaration for java.util.Scanner class − This class ...
Top answer
1 of 3
4

System.in is simply an InputStream. A pretty generic interface designed many years ago. Changing this aspect would break a lot of existing code. So changing the type of System.in is a no go.

Adding the scanner methods to the stream would bloat the existing class on the other hand. Think of concepts such as single responsibility principle or segregation of concerns.

You see - good object oriented design is about having small classes that have one responsibility. Not two, not 5 or 10.

But I think you have a certain point - and if Java would be rewritten today, that input stream might end up being more convenient.

2 of 3
1

Scanner is a class which is defined in the standard Java Class Library, that you can use it to read from the console like this:

Scanner sc = new Scanner(System.in);
    int i = sc.nextInt();

however there are even more options that this constructer can do, for example you can read from a file and not console like this:

Scanner sc = new Scanner(new File("myNumbers"));
  while (sc.hasNextLong()) {
      long aLong = sc.nextLong();
  }

so basically depending on the constructer you can choose where you want to read your input from.

Additionally, there are multiple ways to represent integers in a stream. Scanner.nextInt() reads them as a text string. DataInputStream.readInt() reads them as binary data.

If you mix them up, a human would enter 1234 and get 825373492, or a computer would enter 825373492 and get 1234. Both would be confused. By having to specify Scanner or DataInputStream, there are no such surprises or bugs, because you state up front what "read an integer" means.

Read this: https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html

🌐
Medium
medium.com › @farhan77070 › understanding-the-java-scanner-class-a-complete-guide-3cd33f41dcae
Understanding the Java Scanner Class: A Complete Guide | by Md Farhan Alam | Medium
January 25, 2025 - The Scanner class is part of the java.util package and allows us to capture input from various sources, such as user input from the keyboard, files, or streams.