AP Computer Science A flashcards
AP Computer Science A · Build recall with a focused review session.
32 cards. Read the term and the definition here. The deck at the top of this page is optional.
- Reference variable
- A variable that holds the memory address of an object rather than the object's data. Two references can point to the same object.
- null
- A special reference value meaning no object is referenced. Calling an instance method on a null reference throws NullPointerException at run time.
- Method signature
- The method name plus the ordered list of its parameter types. Return type and parameter names are not part of the signature.
- Pass by value
- Java copies each argument into the parameter. Primitives copy values; object references copy addresses, so the referenced object can be mutated but not reassigned.
- String immutability
- String objects never change after creation. Methods like substring and toUpperCase return new String objects instead of altering the original.
- equals versus == for Strings
- equals compares character content, while == compares reference identity. Two equal Strings created separately may make == false and equals true.
- Integer division
- Dividing two int values discards the fractional part and truncates toward zero, so 7/2 evaluates to 3. Mixing in a double gives a double result.
- Wrapper classes
- Classes such as Integer and Double that hold primitive values as objects. Autoboxing wraps a primitive; unboxing extracts it back.
- Short-circuit evaluation
- The operators && and || may skip their right operand. If the left side of && is false or the left of || is true, the right side is not evaluated.
- De Morgan's laws
- Rules for negating boolean expressions: !(a && b) equals !a || !b, and !(a || b) equals !a && !b.
- if / else if chain
- Conditions are tested top to bottom, and only the first true branch executes. Remaining conditions are skipped once a branch runs.
- for loop header
- Three parts separated by semicolons: initialization, boolean test, and update. The test runs before each iteration and the update after each body.
- while versus do-while
- A while loop tests before the body and may run zero times. A do-while tests after the body and always runs at least once.
- Enhanced for loop
- A loop of the form for (Type x : collection) that visits each element in order. It cannot change the collection's size or array length.
- Off-by-one error
- A loop bound mistake, such as using <= with an index that should stop at length - 1. It often causes an out-of-bounds exception.
- Nested loop iterations
- The inner loop completes all its passes for each single pass of the outer loop, so total iterations equal the product of the two counts.
- Constructor
- A method-like block with the class name and no return type that initializes a new object. Constructors can be overloaded with different parameter lists.
- Default constructor
- A no-argument constructor supplied by the compiler only when the class declares no constructors. Declaring any constructor removes it.
- this reference
- A reference to the current object inside an instance method or constructor. It disambiguates a field from a parameter with the same name.
- static members
- Variables and methods that belong to the class rather than any object. Static methods cannot access instance variables directly or use this.
- Accessor and mutator
- An accessor (getter) returns object state without changing it. A mutator (setter) changes state, often after validating the new value.
- Encapsulation
- Hiding an object's data behind private instance variables and exposing controlled access through public methods, which protects state from invalid outside changes.
- Method overriding
- A subclass method with the same signature as a superclass method. At run time the version matching the object's actual type is called.
- super call
- A call to a superclass constructor, written as super(...) and required to be the first statement in the subclass constructor when used explicitly.
- toString method
- A method returning a String description of an object. It is called automatically when the object is concatenated with a String.
- Array length
- The fixed number of elements in an array, stored in the final field length and accessed without parentheses, as in arr.length.
- Array index bounds
- Valid indices run from 0 to length - 1. Using any other index throws ArrayIndexOutOfBoundsException at run time.
- Default array values
- Elements of a new array are initialized to 0 for numeric types, false for boolean, the null character for char, and null for object references.
- ArrayList methods
- size() returns the count, get(i) and set(i, v) access elements, add(v) appends, add(i, v) inserts, and remove(i) deletes and returns an element.
- ArrayList removal while looping
- Removing an element shifts later elements left, so a forward index loop can skip elements. Decrement the index after removal or loop backward.
- 2D array dimensions
- A 2D array is an array of arrays. arr.length gives the number of rows, and arr[0].length gives the number of columns in the first row.
- ConcurrentModificationException
- Thrown when a collection's size is changed while an enhanced for loop is iterating over it, because the loop's internal state becomes invalid.