TLDR
Libraries are collections of classes, and an API specification is the documentation that tells you how to use those classes without seeing their internal code. In AP Computer Science A, your job is to read that documentation to identify a class's attributes (its data, stored in variables) and its behaviors (what it can do, defined by methods).

Why This Matters for the AP Computer Science A Exam
This topic builds the reading skill you use all over the exam. Both multiple-choice questions and free-response code writing often hand you a class along with descriptions of its methods, and you are expected to use that class correctly even though you never see how it was written. Getting comfortable with attributes, behaviors, packages, and documentation now makes the Math class, the String class, and any provided classes much easier to work with later.
Key Takeaways
- A library is a collection of classes, and an API specification explains how to use those classes.
- API documentation is essential for understanding a class's attributes and behaviors, since you use a class without seeing its internal code.
- Attributes are the data related to a class and are stored in variables; behaviors are what instances can do and are defined by methods.
- A class defines a specific reference type, and existing classes can be used to create objects.
- Classes in APIs and libraries are grouped into packages.
Key Concepts
APIs Tell You How to Use a Class
An application programming interface (API) specification is the documentation that informs the programmer how to use the classes in a library. The "interface" part means it shows you what you can do with a class without revealing how it works internally.
Think of an API like a restaurant menu. The menu lists the dishes and describes them, but it does not hand you the recipes. API documentation works the same way: it tells you what methods a class has and what they do, but not the internal code behind them. This is why you can use a class confidently just by reading its documentation.
Libraries Are Collections of Classes
A library is a collection of classes that you can reuse instead of writing everything from scratch. Existing classes and class libraries can be utilized to create objects, which saves you from rebuilding common functionality yourself.
Each class in a library defines a specific reference type. When you create an object from one of these classes, the variable that holds it stores a reference to that object rather than the object itself.
Packages Group Classes Together
Classes in APIs and libraries are grouped into packages. A package is a way of organizing related classes under a shared name. Package names use dots to show hierarchy, similar to nested folders.
One package worth knowing now is java.lang, which contains fundamental classes like String, Math, and Object. Classes in java.lang are available by default, which is why you can use String and Math without any extra setup.
Attributes and Behaviors
Every class describes two things: attributes and behaviors.
- Attributes are the data related to the class. They are stored in variables.
- Behaviors are what instances of the class can do, or what can be done with them. They are defined by methods.
When you read API documentation, you are really looking for these two things. The variables tell you what data an object holds, and the methods tell you what that object can do.
Code Examples
The classes below come from java.lang, so they are available by default. These examples show how reading a class's documented behaviors lets you use it correctly.
</>Java// Using the Math class from java.lang (available by default) public class MathAPIDemo { public static void main(String[] args) { // Math methods are class methods, so call them on the class name double squareRoot = Math.sqrt(16); // returns 4.0 double power = Math.pow(2, 10); // returns 1024.0 double absoluteValue = Math.abs(-42); // returns 42.0 // random() returns a double >= 0.0 and < 1.0 double random = Math.random(); System.out.println(squareRoot); System.out.println(power); System.out.println(absoluteValue); System.out.println(random); } }
Reading documented behaviors before calling a method:
</>Java// Using documented String behaviors (String is in java.lang) public class StringAPIExample { public static void main(String[] args) { String text = "Hello World"; // int length() returns the number of characters int len = text.length(); // returns 11 // String substring(int from, int to) returns chars from..to-1 String sub = text.substring(0, 5); // returns "Hello" // int indexOf(String str) returns the first index, or -1 if not found int index = text.indexOf("World"); // returns 6 // boolean equals(Object other) compares character sequences boolean same = text.equals("Hello World"); // returns true System.out.println(len); System.out.println(sub); System.out.println(index); System.out.println(same); } }
Notice that you never see the code inside length(), substring(), or Math.sqrt(). You only need the documented behavior to use them correctly.
How to Use This on the AP Computer Science A Exam
Reading a Provided Class
When a question gives you a class, scan its documentation for two things: the attributes (variables that hold data) and the behaviors (methods you can call). You do not need to know how a method is written to use it. You only need to know what it does, what it takes in, and what it returns.
Code Tracing
When you trace code that calls library methods, treat the documented behavior as the source of truth. For a method like substring(int from, int to), the documentation tells you it returns the characters from index from up to but not including to. Trust the description rather than guessing.
Common Trap
Match every method call to what the documentation actually says. Check the parameter types, the order of parameters, and the return type before you assume an output. Many wrong answers come from skipping past these details.
Common Misconceptions
- You need to see a class's internal code to use it. You do not. The API specification gives you the documented attributes and behaviors, which is all you need to use the class.
- An API and a library are the same thing. A library is the collection of classes. The API specification is the documentation that explains how to use those classes.
- Every class must be imported. Classes in
java.lang, such asString,Math, andObject, are available by default and do not need extra setup. - Attributes and behaviors are the same kind of thing. Attributes are data stored in variables, while behaviors are actions defined by methods. Keep the two ideas separate when you read documentation.
- Methods on a String change the original String. They do not. String methods return new values, and the original String object stays the same.
Related AP Computer Science A Guides
Vocabulary
The following words are mentioned explicitly in the College Board Course and Exam Description for this topic.Term | Definition |
|---|---|
API | An application programming interface that provides a specification informing programmers how to use classes and libraries. |
attribute | The data or properties that define the state of an object or class. |
behavior | The methods or actions that an object or class can perform. |
class | A formal implementation or blueprint that defines the attributes and behaviors of objects. |
library | Collections of classes that can be utilized to create objects and are documented in API specifications. |
method | A named block of code that only runs when it is called, allowing programmers to reuse code and organize programs into logical sections. |
object | A specific instance of a class with defined attributes and behaviors. |
package | Organizational groupings of classes within APIs and libraries. |
reference type | A data type that holds a reference (memory address) to an object rather than storing the object's value directly. |
Frequently Asked Questions
What is an API in AP Computer Science A?
An API, or application programming interface, is documentation that tells programmers how to use classes in a library. It lists the class attributes, behaviors, method parameters, and return types you need to use the class correctly.
What is the difference between an API and a library?
A library is the collection of reusable classes. The API specification is the documentation that explains how to use those classes without needing to see their internal code.
What are attributes and behaviors in a class?
Attributes are data related to a class and are stored in variables. Behaviors are actions that instances can do, or actions that can be done with them, and they are defined by methods.
What is a package in Java?
A package groups related classes under a shared name. For example, java.lang contains core classes like String, Math, and Object, which are available by default in AP CSA programs.
Do you need to know the internal code of a library class?
No. The point of an API specification is that you can use a class by reading what its methods do, what parameters they take, and what they return. You do not need the method implementation.
How does API documentation show up on the AP CSA exam?
AP CSA questions often give you a class or method description and expect you to use it correctly. Read the method name, parameter list, return type, and behavior before tracing or writing code.