ACSA Exam Prep
Unit 1 · Using Objects and Methods · Topic 1.7

Application Program Interface (API) and Libraries

Skill 4.A

Big idea: You don't have to write everything yourself. Libraries provide ready-made classes, and the API documentation tells you how to use them without seeing their code.

Learning objectives
  • Identify the attributes and behaviors of a class found in the libraries contained in an API.

Libraries, packages, and APIs

A library is a collection of classes. Related classes are grouped into packages; for example, String and Math are in java.lang, which every program can use without an import. ArrayList, Scanner, and File live in packages you import (java.util, java.io).

An API (Application Program Interface) specification lists each class's constructors and methods: their names, parameters, return types, and what they do.

Attributes and behaviors

Every class defines attributes (the data each object stores, held in variables) and behaviors (what objects can do, defined by methods). Reading documentation means identifying both.

ClassAttributesBehaviors
StringThe sequence of characterslength(), substring, indexOf, equals
ArrayListThe list of elementsadd, get, set, remove, size()
A BankAccount classowner, balancedeposit, withdraw, getBalance
Key points
  • Libraries are collections of classes; an API specification explains how to use them.
  • A class defines a reference type. Classes are grouped into packages.
  • Attributes are data stored in variables. Behaviors are actions defined by methods.
Watch out
  • You can use a class correctly from its documentation alone. On the exam, read the provided method descriptions carefully instead of guessing what a method does.
Exam tip
  • The Java Quick Reference you get on exam day is a small API. Know where each method is so you can look it up quickly.
Quick check
In a Song class with title, artist, and a play() method, which are attributes and which are behaviors?
Show answer
title and artist are attributes; play() is a behavior.