Skip to main content
The new Teacher Workspace is here. Your first 3 assignments are free. Try it →
A colleague sent you $30 off Fiveable. Get the annual plan for $99 →

Package in AP Computer Science A

In AP Computer Science A, a package is a named group of related classes in a Java API or library, such as java.util or java.lang. Packages organize classes and prevent naming conflicts, and they tell you what to import before you can use a class like ArrayList.

Verified for the 2027 AP Computer Science A exam•Last updated October 2026

What is the Package?

A package is how Java organizes its classes into folders. According to EK 1.7.A.1, libraries are collections of classes, and "classes in the APIs and libraries are grouped into packages." So the package is the label on the shelf where a class lives. ArrayList lives in java.util. String and Math live in java.lang.

Why bother grouping them? It keeps thousands of classes manageable, and it lets two classes share a name without colliding, because each one's full name includes its package. Packages also connect to visibility. Classes and members marked public can be used from outside their package. When you look up a class in the API documentation, the first thing it shows you is the package. That tells you where the class comes from and what you need to import.

Why the Package matters in AP® Computer Science A

Packages belong to Topic 1.7 Application Program Interface (API) and Libraries in Unit 1: Using Objects and Methods. They support learning objective AP Comp Sci A 1.7.A, which asks you to identify the attributes and behaviors of a class found in the libraries contained in an API. You can't use a library class until you know where it lives. The package is the address, and the API documentation is the instruction manual. This matters for the rest of the course too, because every time you create an ArrayList or use a Scanner, you're relying on a class from someone else's package.

How the Package connects across the course

Import Statement (Unit 1)

The package tells you where a class lives, and the import statement brings it into your file. Writing import java.util.ArrayList; is basically saying "go to the java.util shelf and grab ArrayList." Classes in java.lang, like String and Math, are imported automatically. That's why you never write an import for them.

Library, Class, and Reference Type (Unit 1)

Think of it as nesting boxes. A library is a collection of classes, and those classes are sorted into packages. Each class defines a reference type you can use to create objects. Once you know the package, you can read the API docs to find the class's attributes and behaviors.

ArrayList and the java.util Package (Unit 4)

ArrayList is the library class you'll use most, and it comes from java.util. When you get to data collections, the package idea from Topic 1.7 pays off. You read the documentation, import the class, call its constructor, and use methods like add.

Public and Private Access Modifiers (Unit 3)

Packages draw a boundary, and access modifiers decide who can cross it. A public class or method can be used by code in any package, which is why you can call ArrayList's methods from your own program. private members stay hidden inside their own class no matter what package you're in.

Is the Package on the AP® Computer Science A exam?

No released FRQ has used the word "package" verbatim, but the idea sits underneath any FRQ that uses library classes like ArrayList or String. In multiple choice, packages usually show up in API-reading questions. A typical stem shows a documentation snippet (for example, that ArrayList is in java.util, with a constructor ArrayList() and a method boolean add(E e)). It then asks which code segment correctly uses the class. To get it right, connect the package to the correct import, call the constructor properly, and use the method the way its signature says. Related questions ask you to tell attributes (data stored in variables) apart from behaviors (methods like add()), or to define what a class is. Those are the core of LO 1.7.A.

The Package vs Library

A library is a collection of classes you can reuse. A package is the named grouping those classes are organized into. The Java library contains many packages, like java.util and java.lang, and each package contains related classes. So the library is the whole bookstore and a package is one labeled section. On the exam, you import from a package, not from "a library" in general.

Key things to remember about the Package

  • A package is a named group of related classes in a Java API or library, such as java.util or java.lang.

  • EK 1.7.A.1 states that classes in APIs and libraries are grouped into packages, and that documentation explains how to use those classes.

  • Knowing a class's package tells you which import statement you need, like import java.util.ArrayList;.

  • Classes in java.lang, including String and Math, are available automatically without an import.

  • Packages prevent naming conflicts because a class's full name includes the package it belongs to.

  • On the exam, you'll read API documentation to identify a class's package, constructors, attributes, and behaviors, then pick code that uses them correctly.

Frequently asked questions about the Package

What is a package in AP Computer Science A?

A package is a named group of related classes in a Java library or API. For example, ArrayList is in java.util and String is in java.lang. Topic 1.7 covers how packages organize the classes you use to create objects.

Do I need to import every class I use in Java?

No. Classes in the java.lang package, like String and Math, are imported automatically. Classes from other packages, like ArrayList from java.util, need an import statement such as import java.util.ArrayList;.

What is the difference between a package and a library in Java?

A library is a collection of reusable classes, and packages are the named groups those classes are sorted into. The Java library holds many packages, and each package holds related classes.

Is a package the same thing as a class?

No. A class defines a reference type with attributes and behaviors, while a package is a container that groups related classes. ArrayList is a class, and java.util is the package that holds it.

Are packages on the AP CSA exam?

Yes, mostly indirectly through Topic 1.7 and LO 1.7.A. Multiple-choice questions may show API documentation listing a class's package, constructor, and methods, then ask which code segment uses the class correctly.