---
title: "Scanner Class — AP Comp Sci A Definition & Exam Guide"
description: "The Scanner class reads input from the keyboard or files in Java. Learn how it works, how it connects to data types and loops, and why the AP exam skips it."
canonical: "https://fiveable.me/ap-comp-sci-a/key-terms/scanner-class"
type: "key-term"
subject: "AP Computer Science A"
unit: "Unit 2"
---

# Scanner Class — AP Comp Sci A Definition & Exam Guide

## Definition

The Scanner class is a built-in Java class (java.util.Scanner) that reads and parses input from a source like the keyboard (System.in) or a file, with methods like nextInt() and nextLine() that convert raw input into typed values. It's standard in AP CSA classrooms but is not tested on the AP exam.

## What It Is

The Scanner class is Java's go-to tool for reading [input](/ap-comp-sci-a/unit-1/14-assignment-statement-input/study-guide/compoundassignment "fv-autolink"). You create one by wrapping an input source, usually `new Scanner(System.in)` for keyboard input, and then call methods like `nextInt()`, `nextDouble()`, or `nextLine()` to pull values out of it. The big idea is that Scanner is a *parser*. The raw input stream is just a sequence of characters, and Scanner is the [object](/ap-comp-sci-a/key-terms/object "fv-autolink") that chops that stream into tokens and converts them into the data types your program actually needs.

Here's the honest AP framing. Scanner does not appear in the [AP Computer Science A](/ap-comp-sci-a "fv-autolink") Course and Exam Description, and the exam never asks you to read keyboard input. On FRQs, data arrives through method parameters and constructor arguments instead. So why learn it? Because almost every classroom project, lab, and textbook exercise uses Scanner to make programs interactive, and using it correctly forces you to practice the concepts the exam *does* test, like calling methods on an object, matching return values to variable types, and controlling loops with user input.

## Why It Matters

Scanner shows up early in most AP CSA courses, right alongside the [Unit 1](/ap-comp-sci-a/unit-1 "fv-autolink") material on variables, data types, and calling methods on objects. Even though no CED learning objective requires it, it's one of the first real objects you ever instantiate with `new`, which makes it a hands-on preview of the object-oriented ideas the course builds toward. Every Scanner call also reinforces type discipline. If you call `nextInt()`, you get an `int` back, and storing it in the wrong type is exactly the kind of compile-error reasoning the exam loves. Later, when you hit loops in Unit 4, Scanner becomes the classic way to practice sentinel-controlled loops, where you keep reading input until the user types a stop value. Mess up that [loop condition](/ap-comp-sci-a/key-terms/loop-condition "fv-autolink") and you've written yourself an infinite loop, which is a genuinely tested concept.

## Connections

### Input stream (Unit 1)

An input stream like System.in is the raw pipe of characters coming into your program. Scanner is the machine you bolt onto that pipe to turn the character soup into usable ints, doubles, and Strings. One is the source, the other is the reader.

### nextInt() and Data Type (Unit 1)

Each Scanner method has a [return type](/ap-comp-sci-a/key-terms/return-type "fv-autolink") baked into its name. nextInt() returns an int, nextDouble() returns a double, nextLine() returns a String. Matching a method's return type to the variable that catches it is a skill the exam tests constantly, even without Scanner in the question.

### Infinite Loop and Loop Structure (Unit 4)

Scanner is the classic engine for sentinel-controlled loops, like reading numbers until the user enters -1. If you forget to call nextInt() again inside the [loop body](/ap-comp-sci-a/key-terms/loop-body "fv-autolink"), the condition never changes and you've built an infinite loop. That bug pattern, a loop variable that never updates, is exactly what MCQs probe.

### close() (Unit 2)

Scanner objects hold onto a system resource, so good style is calling scanner.close() when you're done reading. It's a small habit, but it's a concrete example of calling a void method on an object, which is core [Unit 2](/ap-comp-sci-a/unit-2 "fv-autolink") territory.

## On the AP Exam

Direct answer first. The Scanner class is not on the AP Computer Science A exam. The CED does not include console input, and FRQs hand you data through parameters, constructors, and return values instead of asking you to read it in. No multiple-choice question will require you to know Scanner's methods. That said, the skills Scanner builds are absolutely tested. You'll see MCQs about whether a value returned by a method can be stored in a given variable type, FRQs where you must use a parameter the way you'd use a value read from input, and questions about loop conditions where the same logic error that breaks a Scanner loop (never updating the variable in the condition) creates an infinite loop. Treat Scanner as practice equipment, not exam content.

## Scanner class vs System.in (the input stream)

System.in is the raw input stream, a plain sequence of bytes coming from the keyboard with no idea what an int or a String is. Scanner is the class you wrap around that stream to parse it into typed values. You can't call nextInt() on System.in directly; you need a Scanner to do the interpreting. Stream supplies the data, Scanner makes sense of it.

## Key Takeaways

- The Scanner class reads and parses input from a source like System.in or a file, converting raw characters into typed values such as ints, doubles, and Strings.
- Scanner is not in the AP CSA CED and never appears on the exam, where FRQs pass data in through method parameters and constructors instead.
- Each Scanner method has a fixed return type, so nextInt() returns an int and nextLine() returns a String, and mixing those up causes the kind of type errors the exam does test.
- Scanner is the standard tool for sentinel-controlled loops in class, and forgetting to read new input inside the loop body creates an infinite loop.
- Creating a Scanner with new Scanner(System.in) is often your first hands-on experience instantiating an object, which previews the object-oriented skills in Units 2 and 5.

## FAQs

### What is the Scanner class in Java?

Scanner is a built-in Java class in java.util that reads input from a source like the keyboard (System.in) or a file. You create one with new Scanner(System.in) and call methods like nextInt(), nextDouble(), and nextLine() to read typed values.

### Is the Scanner class on the AP Computer Science A exam?

No. Scanner is not part of the AP CSA Course and Exam Description, and no exam question requires reading keyboard input. FRQs give you data through method parameters and constructors instead, so you'll use Scanner in class but never on test day.

### What's the difference between Scanner and System.in?

System.in is the raw input stream, just a flow of characters from the keyboard. Scanner is the class that wraps that stream and parses it into actual data types. You need both together, since the stream alone can't give you an int.

### Why does nextInt() followed by nextLine() skip my input?

nextInt() reads the number but leaves the newline character sitting in the stream, so the next nextLine() call grabs that leftover newline and returns an empty String. The classic fix is calling an extra nextLine() to clear the buffer. This is a famous classroom bug, but since Scanner isn't on the exam, you'll only fight it in your own projects.

### Do I need to close a Scanner?

It's good practice. Calling scanner.close() releases the underlying input stream when you're done reading. Your program usually works without it in small labs, but closing resources is a habit worth building, and it's a clean example of calling a void method on an object.

## Related Study Guides

- [2.7 While Loops](/ap-comp-sci-a/unit-2/while-loops/study-guide/7qGsGOh1UKALAWpJhZOi)

## Structured Data

```json
{"@context":"https://schema.org","@graph":[{"@type":"LearningResource","@id":"https://fiveable.me/ap-comp-sci-a/key-terms/scanner-class#resource","name":"Scanner Class — AP Comp Sci A Definition & Exam Guide","url":"https://fiveable.me/ap-comp-sci-a/key-terms/scanner-class","learningResourceType":"Concept explainer","educationalLevel":"AP / High School","about":{"@id":"https://fiveable.me/ap-comp-sci-a/key-terms/scanner-class#term"},"audience":{"@type":"EducationalAudience","educationalRole":"student"},"dateModified":"2026-06-11T00:50:33.311Z","isPartOf":{"@type":"Collection","name":"AP Computer Science A Key Terms","url":"https://fiveable.me/ap-comp-sci-a/key-terms"},"publisher":{"@type":"Organization","name":"Fiveable","url":"https://fiveable.me"}},{"@type":"DefinedTerm","@id":"https://fiveable.me/ap-comp-sci-a/key-terms/scanner-class#term","name":"Scanner class","description":"The Scanner class is a built-in Java class (java.util.Scanner) that reads and parses input from a source like the keyboard (System.in) or a file, with methods like nextInt() and nextLine() that convert raw input into typed values. It's standard in AP CSA classrooms but is not tested on the AP exam.","url":"https://fiveable.me/ap-comp-sci-a/key-terms/scanner-class","inDefinedTermSet":{"@type":"DefinedTermSet","name":"AP Computer Science A Key Terms","url":"https://fiveable.me/ap-comp-sci-a/key-terms"}},{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"What is the Scanner class in Java?","acceptedAnswer":{"@type":"Answer","text":"Scanner is a built-in Java class in java.util that reads input from a source like the keyboard (System.in) or a file. You create one with new Scanner(System.in) and call methods like nextInt(), nextDouble(), and nextLine() to read typed values."}},{"@type":"Question","name":"Is the Scanner class on the AP Computer Science A exam?","acceptedAnswer":{"@type":"Answer","text":"No. Scanner is not part of the AP CSA Course and Exam Description, and no exam question requires reading keyboard input. FRQs give you data through method parameters and constructors instead, so you'll use Scanner in class but never on test day."}},{"@type":"Question","name":"What's the difference between Scanner and System.in?","acceptedAnswer":{"@type":"Answer","text":"System.in is the raw input stream, just a flow of characters from the keyboard. Scanner is the class that wraps that stream and parses it into actual data types. You need both together, since the stream alone can't give you an int."}},{"@type":"Question","name":"Why does nextInt() followed by nextLine() skip my input?","acceptedAnswer":{"@type":"Answer","text":"nextInt() reads the number but leaves the newline character sitting in the stream, so the next nextLine() call grabs that leftover newline and returns an empty String. The classic fix is calling an extra nextLine() to clear the buffer. This is a famous classroom bug, but since Scanner isn't on the exam, you'll only fight it in your own projects."}},{"@type":"Question","name":"Do I need to close a Scanner?","acceptedAnswer":{"@type":"Answer","text":"It's good practice. Calling scanner.close() releases the underlying input stream when you're done reading. Your program usually works without it in small labs, but closing resources is a habit worth building, and it's a clean example of calling a void method on an object."}}]},{"@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"AP Computer Science A","item":"https://fiveable.me/ap-comp-sci-a"},{"@type":"ListItem","position":2,"name":"Key Terms","item":"https://fiveable.me/ap-comp-sci-a/key-terms"},{"@type":"ListItem","position":3,"name":"Unit 2","item":"https://fiveable.me/ap-comp-sci-a/unit-2"},{"@type":"ListItem","position":4,"name":"Scanner class"}]}]}
```
