AP CSP
AP Computer Science Principles / All lessons / Big Idea 3: Algorithms and Programming
3Big Idea 3: Algorithms and Programming
AP CSP topic 3.14

Libraries

A software library is a collection of procedures that others have already written and tested, such as tools for math, graphics, or maps. Libraries save time because you do not rebuild common tasks. An API, or application program interface, is the documentation that explains what each procedure does, what inputs it needs, and what it returns.

Libraries vocabulary

  • Library: A collection of prewritten procedures that can be used in new programs.
  • API: Application program interface: the specification for how to use a library's procedures.
  • Documentation: A description of how a procedure behaves and how to use it.
  • Reuse: Using existing tested code instead of writing it again.

AP-style practice questions

Try each one, then open the answer. To save your progress, take this quiz in the interactive course.

Skill: Abstraction in Program Development

1. Which of the following best describes an API?

  1. (A) A type of computer virus
  2. (B) Documentation that explains how to use the procedures in a library
  3. (C) A list of all programs on a computer
  4. (D) A kind of compression
Show answer

(B) Documentation that explains how to use the procedures in a library An API specifies how to use a library's procedures, their inputs and outputs.

Skill: Abstraction in Program Development

2. A student uses a mapping library to show locations in their app instead of writing map code from scratch. Which of the following is the main benefit?

  1. (A) The app will have no errors
  2. (B) The student saves time by reusing tested code
  3. (C) The app will not need any data
  4. (D) The student owns the library
Show answer

(B) The student saves time by reusing tested code Libraries let programmers reuse existing, tested procedures.

Skill: Abstraction in Program Development
From a library's documentation:
round(x, places) returns x rounded to the given number of decimal places.

3. What does round(3.14159, 2) return?

  1. (A) 3
  2. (B) 3.1
  3. (C) 3.14
  4. (D) 3.142
Show answer

(C) 3.14 Rounded to 2 decimal places, 3.14159 becomes 3.14.

Skill: Computational Solution Design

4. Which of the following is the most important thing to check before using a procedure from a library?

  1. (A) How many lines of code it has
  2. (B) What inputs it needs and what it returns, as described in its documentation
  3. (C) The name of the person who wrote it
  4. (D) Whether its code is written in color
Show answer

(B) What inputs it needs and what it returns, as described in its documentation The documentation tells you how to call the procedure correctly.

Open 3.14 in the interactive course