AP® Computer Science A review sheet from Aim for Five (aimforfive.com/csa/units/1)
Unit 1
15–25% of examUsing Objects and Methods
Unit 1 is where you start writing Java: storing values in variables, doing arithmetic, and printing results. Then you move on to objects, which bundle data with the methods that act on it, and you practice calling methods from Java's built-in classes like Math and String. Almost every line of code you write later uses these basics.
Study this unit
Flashcards (40)Practice questions (68)Computer Science A must-know sheetFree-response questions on this unit
Write your own answer, then score it with the rubric or with AI.
- Question 1: Methods and Control StructuresTrain route delays and station codes7 points · about 25 minutes
- Question 1: Methods and Control StructuresDigit-sum puzzle and mirror strings7 points · about 25 minutes
- Question 1: Methods and Control StructuresRewards card constructor and top item7 points · about 25 minutes
- Question 1: Methods and Control StructuresNetwork outages and hidden email addresses7 points · about 25 minutes
- Question 1: Methods and Control StructuresAverage with the lowest score dropped, and name formatting7 points · about 25 minutes
- Question 4: 2D ArrayFilling a letter grid from a String6 points · about 22 minutes
Big ideas
- A program is an algorithm written in a language the compiler can check and the computer can run
- Every variable has a type, and the type decides what values it can hold and what operations work on it
intdivision throws away the remainder, so the types in an expression change the answer- Methods let you use code by knowing what it does, not how it does it
- Objects are instances of classes, and variables hold references to them
Full unit reviews
Longer videos that cover the whole unit. Good for a first pass or a final review.
Topics
- 1.1: Introduction to Algorithms, Programming, and Compilers
- 1.2: Variables and Data Types
- 1.3: Expressions and Output
- 1.4: Assignment Statements and Input
- 1.5: Casting and Range of Variables
- 1.6: Compound Assignment Operators
- 1.7: Application Program Interface (API) and Libraries
- 1.8: Documentation with Comments
- 1.9: Method Signatures
- 1.10: Calling Class Methods
- 1.11: Math Class
- 1.12: Objects: Instances of Classes
- 1.13: Object Creation and Storage (Instantiation)
- 1.14: Calling Instance Methods
- 1.15: String Manipulation
An algorithm is a step-by-step process, and the order of the steps matters. You write Java in an editor or IDE, and the compiler checks for syntax errors before the program can run. Testing catches logic errors (wrong results) and run-time errors, which stop the program while it runs; an exception is one kind of run-time error.
Key terms
- algorithm
- sequencing
- compiler
- syntax error
- logic error
- run-time error and exception
A few quick questions on this topic, with the answers explained.
A data type tells Java what kind of values something can hold and which operations work on them. This course uses three primitive types: int (whole numbers), double (decimal numbers) and boolean (true or false). Everything else, like String, is a reference type. A variable is a named storage spot with a fixed type, and its value can change while the program runs.
Key terms
- data type
- primitive type
- reference type
intdoubleboolean- variable
A few quick questions on this topic, with the answers explained.
System.out.println prints and then moves to a new line, while System.out.print stays on the same line. Inside a string literal, the escape sequences \", \\ and \n stand for a quote, a backslash and a new line. Arithmetic uses + - * / %, with *, / and % before + and -; two int values give an int result, so 7 / 2 is 3 and 7 % 2 is 1, but if either value is a double the result is a double. Dividing an int by zero throws an ArithmeticException.
Key terms
- string literal
- escape sequence
- integer division
- remainder operator
% - operator precedence
ArithmeticException
A few quick questions on this topic, with the answers explained.
The = operator works out the value on the right and stores it in the variable on the left, so x = x + 1 is a normal statement, not a contradiction. A variable must get a value before you use it, and a reference variable can hold null when it points to no object. The Scanner class is one way to read input, though the exam doesn't test any specific kind of input.
Key terms
- assignment operator
- initialize
- expression
nullScanner
A few quick questions on this topic, with the answers explained.
Casting converts between int and double: (int) 3.9 is 3 because casting to int cuts off the decimal part, and (int) (x + 0.5) rounds a non-negative x. An int only holds values from Integer.MIN_VALUE to Integer.MAX_VALUE, so going past either end causes overflow, and double math can have small round-off errors.
Key terms
- casting
- truncation
- widening
Integer.MAX_VALUE- integer overflow
- round-off error
A few quick questions on this topic, with the answers explained.
Compound assignment operators like +=, -=, *=, /= and %= do the math with the variable's current value and store the result back in it, so score += 5 adds 5 to score. count++ adds 1 and count-- subtracts 1; on the exam they appear only as stand-alone statements after the variable.
Key terms
- compound assignment operator
+=- increment
++ - decrement
--
A few quick questions on this topic, with the answers explained.
A library is a collection of ready-made classes grouped into packages, and its API documentation tells you how to use them. Each class describes attributes (the data an object stores in variables) and behaviors (what it can do, written as methods).
Key terms
- library
- API
- package
- class
- attribute
- behavior
A few quick questions on this topic, with the answers explained.
Comments explain code to people and are ignored by the compiler: // for one line, /* */ for a block and /** */ for Javadoc. A precondition is what must be true before a method runs (the method doesn't check it), and a postcondition is what will be true after it finishes.
Key terms
- comment
- Javadoc
- precondition
- postcondition
A few quick questions on this topic, with the answers explained.
A method is a named chunk of code that does nothing until you call it, and procedural abstraction means you can use it knowing only what it does. Its signature is the method's name followed by its parameter types, in order; methods can share a name (overloading) as long as their parameter lists differ. A void method returns nothing, a non-void method hands back a value you should store or use, and each parameter starts as a copy of its argument (call by value).
Key terms
- method
- parameter
- argument
- method signature
- overloading
- call by value
- procedural abstraction
A few quick questions on this topic, with the answers explained.
Class methods have static in their header and belong to the class, not to any one object. You usually call them with the class name and a dot, like Math.sqrt(16.0); inside the class that defines the method, you can leave the class name off.
Key terms
- class method
static- dot operator
A few quick questions on this topic, with the answers explained.
Math Class
The Math class is available without an import and has only static methods. You need Math.abs, Math.pow, Math.sqrt and Math.random; Math.random() gives a double from 0.0 up to but not including 1.0, so (int) (Math.random() * 6) + 1 gives a random whole number from 1 to 6.
Key terms
MathclassMath.absMath.powMath.sqrtMath.random- inclusive vs. exclusive
A few quick questions on this topic, with the answers explained.
A class is a blueprint, and an object is one specific instance built from it. Classes can form a hierarchy where a subclass inherits from a superclass, and every class in Java is a subclass of Object. A reference-type variable doesn't hold the object itself: it holds a reference, which works like the object's address in memory.
Key terms
- class
- object
- instance
- superclass
- subclass
- object reference
A few quick questions on this topic, with the answers explained.
You create an object with new followed by a constructor call, like new Dog("Rex", 3). A constructor has the same name as its class, a class can have overloaded constructors with different parameter lists, and the arguments you pass must match the parameter types in number and order. A reference variable that points to no object holds null.
Key terms
- constructor
new- instantiation
- constructor signature
- overloaded constructors
null
A few quick questions on this topic, with the answers explained.
Instance methods are called on a particular object with the dot operator, like myDog.bark(), and they work with that object's data. If the variable holds null instead of an object, calling a method on it throws a NullPointerException.
Key terms
- instance method
- dot operator
NullPointerException
A few quick questions on this topic, with the answers explained.
A String is an object holding a sequence of characters, and it's immutable: methods like substring return a new string instead of changing the old one. Indexes run from 0 to length() - 1, and going outside them throws a StringIndexOutOfBoundsException. substring(a, b) gives the characters from index a up to but not including b, indexOf returns -1 when there's no match, and you compare strings with equals and compareTo, not ==.
Key terms
- immutable
- concatenation
- index
substringindexOfequalsandcompareTo
A few quick questions on this topic, with the answers explained.