Cram Time

Courses › AP Math and CS

AP Computer Science A

Java programming: classes, control flow, arrays, ArrayList, inheritance, recursion, sorting, and searching.

APAP Math and CS5 units72 items

Study AP Computer Science A freeOpen in the app

Study it the fast way. Sign up free to turn this guide into flashcards, quick drills, practice quizzes and full practice tests that focus on what you miss, track your streak and race classmates live.

Primitive types and objects

Key terms

Primitive type
a basic data type such as int, double, or boolean, not an object
Variable
a named memory location that holds a value
Casting
converting a value from one type to another, such as (int) 3.7
Integer division
division of two ints, which discards the fractional part
Modulus operator
% returns the remainder after division
Object
an instance of a class with its own state and behavior
Constructor
a special method that initializes a new object
Method call
invoking an object's behavior using the dot operator

Key facts

  1. The result of 7 / 2 in Java is 3
  2. The result of 7 % 3 in Java is 1
  3. The keyword used to create a new object is new
  4. A String variable with no object assigned holds the value null
  5. The method that returns the number of characters in a String is length
  6. The first index of a String or array is 0
  7. The Math method that returns a random double from 0.0 up to but not including 1.0 is Math.random

Boolean logic and control flow

Key terms

Boolean expression
an expression that evaluates to true or false
Short-circuit evaluation
skipping the second operand of && or || when the result is already known
if statement
runs a block of code only when its condition is true
for loop
a loop with initialization, condition, and update in one header
while loop
a loop that repeats as long as its condition is true
Infinite loop
a loop whose condition never becomes false
Off-by-one error
a loop or index mistake that runs one time too many or too few
De Morgan's law
!(A && B) is equivalent to !A || !B

Key facts

  1. The logical AND operator in Java is &&
  2. The operator used to test equality of two ints is ==
  3. Two String objects should be compared for equal content with the equals method
  4. The loop for (int i = 0; i < 5; i++) runs 5 times
  5. The keyword that immediately exits a loop is break
  6. The negation of (x > 3) is x <= 3

Classes and methods

Key terms

Class
a blueprint that defines the data and behavior of objects
Instance variable
a field belonging to each individual object
Encapsulation
hiding data by making fields private and exposing public methods
Accessor method
a method that returns the value of a private field
Mutator method
a method that changes the value of a private field
Static method
a method that belongs to the class rather than to any object
Overloading
defining methods with the same name but different parameter lists
Scope
the region of code in which a variable can be used

Key facts

  1. The keyword that refers to the current object is this
  2. The return type of a method that returns nothing is void
  3. Instance variables are usually declared with the access modifier private
  4. Java passes object references by value
  5. A constructor has the same name as its class
  6. A method that always returns the same result for the same input and has no side effects is called pure

Arrays, ArrayList, and algorithms

Key terms

Array
a fixed-size ordered collection of elements of one type
ArrayList
a resizable list class in the java.util package
Traversal
visiting each element of a collection in order
Enhanced for loop
a loop that visits each element without using an index
Linear search
checking each element in order until the target is found
Binary search
repeatedly halving a sorted list to find a target
Selection sort
a sort that repeatedly selects the smallest remaining element and places it
Insertion sort
a sort that inserts each element into its correct place among those already sorted
Merge sort
a divide-and-conquer sort that splits, sorts, and merges halves

Key facts

  1. The number of elements in an array named arr is arr.length
  2. The ArrayList method that adds an element at the end is add
  3. The ArrayList method that returns its number of elements is size
  4. Binary search requires the data to be sorted
  5. Accessing arr[arr.length] throws an ArrayIndexOutOfBoundsException
  6. The worst-case number of steps for binary search on n items is proportional to log base 2 of n

Inheritance and recursion

Key terms

Inheritance
a relationship in which a subclass acquires the members of a superclass
Superclass
the parent class that a subclass extends
Polymorphism
calling the overridden version of a method based on the actual object type
Overriding
a subclass providing its own version of an inherited method
Abstract class
a class that cannot be instantiated and may contain abstract methods
Interface
a type that declares methods a class must implement
Recursion
a technique in which a method calls itself
Base case
the condition that stops a recursive method

Key facts

  1. The keyword used to make a subclass inherit from a superclass is extends
  2. The keyword used to call a superclass constructor is super
  3. The keyword used by a class to promise an interface's methods is implements
  4. Every Java class implicitly extends the class Object
  5. A recursive method without a reachable base case causes a StackOverflowError
  6. The value of factorial(4) computed recursively is 24

More AP Math and CS courses

AP Calculus ABLimits, derivatives and integrals of single-variable functions, with applications and the Fundamental Theorem of Calculus.AP Calculus BCEverything in AB plus parametric, polar and vector calculus, advanced integration, Euler's method and infinite series.AP PrecalculusFunctions and their behavior: polynomial, rational, exponential, logarithmic, trigonometric, polar, parametric, vector and matrix topics.AP StatisticsDescribing data, designing studies, probability, and inference for proportions, means, and relationships.AP Computer Science PrinciplesCreative development, data, algorithms, computing systems and networks, and the impact of computing.