Import Statement

An import statement in Java (e.g., import java.util.ArrayList;) tells the compiler where to find a class from another package so you can use its short name instead of its fully qualified name. On the AP CSA exam, imports are assumed, so you never lose points for omitting them in FRQs.

Verified for the 2027 AP Computer Science A examLast updated June 2026

What is Import Statement?

An import statement is a line at the top of a Java file, like import java.util.ArrayList;, that pulls a class from another package into your program. Without it, you'd have to write the fully qualified name every single time, so java.util.ArrayList instead of just ArrayList. The import is basically a shortcut that says "when I write ArrayList, I mean the one in java.util."

Java automatically imports everything in the java.lang package, which is why you can use String, Math, Integer, and System.out without any import at all. Classes outside java.lang, most famously ArrayList in java.util, technically need an import in real code. Here's the AP-specific part though: the exam assumes all necessary imports are already in place. You'll see code using ArrayList on the exam with no import shown, and when you write FRQ solutions, you should skip imports entirely and jump straight to the method or class you're asked to write.

Why Import Statement matters in AP Computer Science A

Import statements show up the moment you start working with ArrayList in Unit 7, because ArrayList lives in java.util rather than the auto-imported java.lang. Understanding imports also helps you read any real Java code your teacher or IDE throws at you, since the import lines at the top are a quick map of which libraries the program depends on. The bigger conceptual win is that imports teach you how Java organizes code into packages, which is the foundation for understanding why some classes (like String and Math) work out of the box while others don't. Just remember the exam's stance, which is that imports are background plumbing, not something you're graded on writing.

How Import Statement connects across the course

Package (Unit 7 context)

Packages are the folders Java uses to organize classes, and an import statement is how you reach into one of those folders. java.util is a package; import java.util.ArrayList; grabs one class out of it. You can't really understand imports without packages, since an import is just a package address plus a class name.

ArrayList constructor (Unit 7)

This is the one place AP CSA actually bumps into imports. Before you can call new ArrayList<Integer>(), real Java code needs import java.util.ArrayList; because ArrayList isn't in java.lang. On the exam that import is assumed, but in your own IDE, forgetting it is the classic 'cannot find symbol' error.

Static Import (beyond the AP subset)

A regular import brings in a class name; a static import brings in a class's static members directly, so you could write sqrt(x) instead of Math.sqrt(x). AP CSA never requires static imports, and you should write Math.sqrt the normal way on the exam.

Classpath (beyond the AP subset)

The import statement tells the compiler which class you mean, but the classpath tells the JVM where to actually find that class's compiled file on your computer. Imports are addresses; the classpath is the road map. This distinction matters in real development, not on the AP exam.

Is Import Statement on the AP Computer Science A exam?

Import statements are essentially exam-proof, in a good way. FRQ instructions assume any needed imports are present, so you should never write import java.util.ArrayList; at the top of an FRQ answer, and you'll never be penalized for leaving it out. MCQ code segments likewise show classes like ArrayList already usable without imports shown. What you actually need is the concept behind it: know that java.lang classes (String, Math, Integer, Double) are always available, know that ArrayList comes from java.util, and don't waste FRQ time on boilerplate. Spend that time on the logic the rubric actually scores, like traversals and method implementations.

Import Statement vs Static Import

A regular import statement brings a class name into scope, so import java.util.ArrayList; lets you write ArrayList instead of java.util.ArrayList. A static import brings a class's static members into scope, so import static java.lang.Math.sqrt; would let you write sqrt(16) instead of Math.sqrt(16). AP CSA uses neither in your answers, and exam code always calls static methods with the class name attached, like Math.pow and Math.random.

Key things to remember about Import Statement

  • An import statement lets you use a class's short name (ArrayList) instead of its fully qualified name (java.util.ArrayList).

  • Java automatically imports the java.lang package, which is why String, Math, and Integer never need an import.

  • ArrayList lives in java.util, so real Java code needs import java.util.ArrayList; before using it.

  • On the AP CSA exam, all necessary imports are assumed, so never write import statements in your FRQ answers.

  • Forgetting an import in your own IDE causes a 'cannot find symbol' compile error, which is a compile-time problem, not a runtime exception.

  • An import doesn't copy code into your file; it just tells the compiler which package to look in when it sees a class name.

Frequently asked questions about Import Statement

What is an import statement in Java?

It's a line at the top of a Java file, like import java.util.ArrayList;, that tells the compiler where to find a class from another package so you can refer to it by its short name. Without it, you'd have to write the full name java.util.ArrayList every time.

Do I need to write import statements on the AP Computer Science A exam?

No. The exam assumes all necessary imports are already in place, so FRQ solutions should never include them and you won't lose points for leaving them out. Jump straight to the method or class the question asks for.

Why doesn't String or Math need an import statement?

Because they live in the java.lang package, which Java imports automatically into every program. That's the same reason Integer, Double, and System work without any import line.

What's the difference between an import and a static import?

A regular import brings in a class name (so you can write ArrayList), while a static import brings in a class's static members directly (so you could write sqrt(x) instead of Math.sqrt(x)). AP CSA only ever shows regular usage, and you should always write Math.sqrt, Math.pow, etc. with the class name.

Does forgetting an import statement cause a runtime exception?

No, it causes a compile-time error, typically 'cannot find symbol,' which means your code never runs at all. Runtime exceptions like NullPointerException or IndexOutOfBoundsException happen while the program is running, which is a different category of error.