๐Ÿ“– Crammy ยท All study guides
AP Computer Science A ยท Unit 2

Using Objects: every key term you need

13 flashcard terms for AP Computer Science A Unit 2, written to match the course framework. Study them here, then drill them as interactive flashcards โ€” free, no account needed.

Study this unit free โ†’
Objects
Instance of a class; contains data (fields) and behavior (methods). Created with new keyword: Dog myDog = new Dog();
Classes
Blueprint for objects; defines fields (data) and methods (behavior). Example: class Dog { int age; void bark() {} }
References vs Primitives
Primitive: stores actual value. Reference (object): stores memory address pointing to object. Different behavior for assignment/comparison.
null Reference
Reference pointing to no object. Causes NullPointerException if you try to use it. Check with if (obj != null).
String Class
Immutable sequence of characters. Methods: length(), charAt(index), substring(start, end), indexOf(char), equals(), compareTo().
String Concatenation
+ operator joins strings: \"Hello\" + \"World\" = \"HelloWorld\". Also converts primitives: \"Age: \" + 25 = \"Age: 25\".
String Methods
toUpperCase(), toLowerCase(), trim(), split(delimiter), startsWith(), endsWith(), replace(). Each returns new String (immutable).
ArrayList
Resizable array; stores object references. ArrayList<Integer> list = new ArrayList<>(); Access with get(index), add(element), remove(index).
ArrayList vs Array
Array: fixed size, faster. ArrayList: dynamic size, slower. ArrayList more convenient for unknown sizes.
Method Calling
object.method(arguments). Example: myString.length() returns length. Methods act on object (implicit 'this').
Constructor
Special method creating objects; same name as class. Can have parameters. Default no-arg constructor provided if none written.
toString() Method
Returns String representation of object; automatically called when printing. Override in custom classes for meaningful output.
Unit 2 Summary
Objects contain data (fields) and methods. References store memory addresses. Strings immutable; ArrayList resizable. Constructors initialize objects.
Turn these into flashcards & quizzes โ†’

More AP Computer Science A guides