Dove's LibraryDove's Library

1.7 - Application Program Interface (API) and Libraries

A library is a collection of classes. An API (application programming interface) is the documentation that tells you how to actually use those classes. Classes in APIs and libraries get organized into packages. You can use existing classes to create objects rather than building everything from scratch.
For example, String and Math are in the java.lang package, which every Java program can use automatically. Classes in other packages need an import statement at the top of the file, like Scanner from java.util:
import java.util.Scanner; // now Scanner can be used in this file String word = "hello"; // String is in java.lang, no import needed
The Java Quick Reference you get on the AP exam is a small piece of the Java API documentation. It lists the constructors and methods of a few classes (String, Integer, Double, Math, ArrayList, File, Scanner, and Object) and what each one does, so you can use them without knowing how they were written.
A class defines a specific reference type. Within a class:
  • Attributes are the data associated with the class, stored in variables.
  • Behaviors are what instances of the class can do, defined by methods.
On the exam, classes are often shown with just their headers and comments, and you have to pick out the attributes and behaviors. For example:
/** A bank account that belongs to one person */ public class BankAccount { private String owner; // attribute private double balance; // attribute /** Adds amount to the balance */ public void deposit(double amount) // behavior { /* implementation not shown */ } /** Returns the current balance */ public double getBalance() // behavior { /* implementation not shown */ } }
The attributes are owner and balance, the data each account stores. The behaviors are deposit and getBalance, what you can do with an account. Library classes work the same way: a String’s attribute is its sequence of characters, and its behaviors are methods like length and substring.

AP® is a registered trademark of the College Board, which is not affiliated with Dove's Library and was not involved in the production of, and does not endorse, this website.

Providing free, high-quality AP notes to help students succeed, earn college credit, and reach their educational goals, ensuring everyone has access to the resources they need.

© 2026 Standard Learning Group, Inc., which operates Dove's Library. All rights reserved.