---
title: "Package — AP Computer Science A Definition & Exam Guide"
description: "A package groups related Java classes into one named unit. On AP CSA, java.lang matters most because it gives you Object, String, and Math without imports."
canonical: "https://fiveable.me/ap-comp-sci-a/key-terms/package"
type: "key-term"
subject: "AP Computer Science A"
---

# Package — AP Computer Science A Definition & Exam Guide

## Definition

In Java, a package is a named group of related classes that keeps code organized and prevents naming conflicts; on AP CSA the one that matters most is java.lang, which is imported automatically and contains core classes like Object, String, and Math.

## What It Is

A package is Java's way of organizing related classes into one labeled folder. Think of it like a folder on your computer. You wouldn't dump every [file](/ap-comp-sci-a/key-terms/file "fv-autolink") onto your desktop, and Java doesn't dump every [class](/ap-comp-sci-a/unit-3/abstraction-and-program-design/study-guide/o9VgVeIpKRYZ7N7rXfUz "fv-autolink") into one giant pile either. Classes that work together (math tools, text tools, data structures) get grouped under one package name, like `java.lang` or `java.util`.

Packages solve two problems. First, naming conflicts. Two different packages can each have a class called `List` without colliding, because the full name includes the package. Second, packages work with [access modifiers](/ap-comp-sci-a/key-terms/access-modifiers "fv-autolink") to control visibility, deciding which classes and members can be seen from outside the package. For AP CSA, you mostly stick to `public` and `private`, but the package is the structure that makes those visibility rules meaningful. The package you need to know cold is `java.lang`, home of the `Object` class, `String`, `Math`, and the wrapper classes. It's imported automatically in every Java file, which is why you never write `import java.lang.String;` at the top of your code.

## Why It Matters

Packages aren't a standalone topic on AP CSA, but they sit underneath things you use constantly. Every time you call `Math.random()`, compare strings with `.lang`. Understanding that `java.lang` is auto-imported explains why those tools just work without any [import statement](/ap-comp-sci-a/key-terms/import-statement "fv-autolink"), while something like `ArrayList` (from `java.util`) needs one.lang`, which is why methods like `equals()` and `toString()` are available on any [object](/ap-comp-sci-a/key-terms/object "fv-autolink") you create.

## Connections

### [java.lang Package (Units 1-2)](/ap-comp-sci-a/key-terms/javalang-package)

This is the package on AP CSA. It contains Object, String, Math, Integer, and [Double](/ap-comp-sci-a/unit-1/expressions-and-assignment-statements/study-guide/01dr6uUPDAn3SjtK2Psr "fv-autolink"), and it's the only package Java imports automatically. If a class works without an import statement, it almost certainly lives here.

### [Import Statement (Unit 6-7)](/ap-comp-sci-a/key-terms/import-statement)

Import statements are how you pull classes from other packages into your file. `import java.util.ArrayList;` tells Java which package to look in. No import needed for `java.lang` classes, which is exactly why MCQs ask about it.

### Public and Private Access Modifiers (Unit 5)

Access modifiers control visibility, and packages are part of the boundary they enforce. AP CSA keeps it simple ([public](/ap-comp-sci-a/key-terms/public "fv-autolink") classes, private instance variables), but the package is the organizational unit those rules are built around.

## On the AP Exam

You won't write your own packages on the AP exam, and no released FRQ has asked about packages directly. They show up in multiple-choice questions as background knowledge. Typical stems ask which package the `Object` class belongs to (answer: `java.lang`), why `java.lang` is automatically imported, or which methods are available on a class like `Rectangle` without any extra imports. The trick in that last type is remembering that every class inherits `equals()` and `toString()` from `Object` for free. So your job is recognition, not construction. Know that `java.lang` is auto-imported, know what lives in it, and know that anything outside it (like `java.util.ArrayList`) needs an import statement.

## Package vs Import Statement

A package is the container; an import statement is how you reach into it. The package is where a class lives (java.lang, java.util), while the import statement is the line of code that lets you use a class from another package by its short name. You never import java.lang because Java does it for you, but you do import java.util.ArrayList because it lives in a different package.

## Key Takeaways

- A package groups related Java classes under one name, like a folder, to keep code organized and avoid naming conflicts.
- The java.lang package is automatically imported into every Java file, so classes like Object, String, and Math never need an import statement.
- The Object class lives in java.
- Classes outside java.lang, like ArrayList in java.util, require an import statement before you can use them by their short name.
- On the AP exam, packages appear in multiple-choice questions about java.lang, auto-importing, and which methods a class inherits from Object.

## FAQs

### What is a package in Java for AP Computer Science A?

A package is a named group of related classes, like a folder for code. It keeps classes organized, prevents naming conflicts, and works with access modifiers to control which classes are visible from outside the group.

### Do I have to import java.lang in Java?

No. The [java.lang package](/ap-comp-sci-a/key-terms/javalang-package "fv-autolink") is automatically imported into every Java file, which is why you can use String, Math, and Object without any import statement. This is a common AP multiple-choice question.

### What package does the Object class belong to?

Object belongs to java.lang. Because java.

### What's the difference between a package and an import statement?

The package is where a class lives; the import is how you access it. ArrayList lives in the java.util package, so you write import java.util.ArrayList; to use it. Classes in java.lang skip this step entirely.

### Do I need to create my own packages on the AP CSA exam?

No. The exam never asks you to write a package declaration. You only need to know that java.lang is auto-imported, recognize what's in it, and understand why other classes need import statements.

## Structured Data

```json
{"@context":"https://schema.org","@graph":[{"@type":"LearningResource","@id":"https://fiveable.me/ap-comp-sci-a/key-terms/package#resource","name":"Package — AP Computer Science A Definition & Exam Guide","url":"https://fiveable.me/ap-comp-sci-a/key-terms/package","learningResourceType":"Concept explainer","educationalLevel":"AP® / High School","about":{"@id":"https://fiveable.me/ap-comp-sci-a/key-terms/package#term"},"audience":{"@type":"EducationalAudience","educationalRole":"student"},"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/package#term","name":"Package","description":"In Java, a package is a named group of related classes that keeps code organized and prevents naming conflicts; on AP CSA the one that matters most is java.lang, which is imported automatically and contains core classes like Object, String, and Math.","url":"https://fiveable.me/ap-comp-sci-a/key-terms/package","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 a package in Java for AP Computer Science A?","acceptedAnswer":{"@type":"Answer","text":"A package is a named group of related classes, like a folder for code. It keeps classes organized, prevents naming conflicts, and works with access modifiers to control which classes are visible from outside the group."}},{"@type":"Question","name":"Do I have to import java.lang in Java?","acceptedAnswer":{"@type":"Answer","text":"No. The [java.lang package](/ap-comp-sci-a/key-terms/javalang-package \"fv-autolink\") is automatically imported into every Java file, which is why you can use String, Math, and Object without any import statement. This is a common AP multiple-choice question."}},{"@type":"Question","name":"What package does the Object class belong to?","acceptedAnswer":{"@type":"Answer","text":"Object belongs to java.lang. Because java."}},{"@type":"Question","name":"What's the difference between a package and an import statement?","acceptedAnswer":{"@type":"Answer","text":"The package is where a class lives; the import is how you access it. ArrayList lives in the java.util package, so you write import java.util.ArrayList; to use it. Classes in java.lang skip this step entirely."}},{"@type":"Question","name":"Do I need to create my own packages on the AP CSA exam?","acceptedAnswer":{"@type":"Answer","text":"No. The exam never asks you to write a package declaration. You only need to know that java.lang is auto-imported, recognize what's in it, and understand why other classes need import statements."}}]},{"@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":"Package"}]}]}
```
