SAT / PSAT
SAT / PSAT Prep
History & Social Science
AP World History AP US History AP European History AP Human Geography AP US Government & Politics AP Psychology AP Macroeconomics AP Microeconomics
English
AP English Language & Composition AP English Literature & Composition
Math & Computer Science
AP Calculus AB/BC AP Precalculus AP Statistics AP Computer Science A AP Computer Science Principles
Sciences
AP Biology AP Chemistry AP Environmental Science AP Physics 1 AP Physics 2
World Languages & Arts
AP Spanish Language AP Art History AP Music Theory Start studying →
Unit 1 · Using Objects & Methods Flashcards Cheat Sheet Essentials Visual Review MC Practice FRQ Practice

AP Computer Science A Unit 1 Visual Review

A topic-by-topic visual walkthrough of Using Objects and Methods — variables, data types, expressions, casting, the Math and String classes, and object creation.

← Back to Unit 1 hub
TOPIC 1.1 Algorithms, Programming & Compilers Key definitions ALGORITHM: a finite, ordered set of steps that solves a problem. PROGRAM: an algorithm written in a language a computer can execute. Java is a compiled language A COMPILER translates your source code into bytecode the computer runs. A SYNTAX error stops compilation — the program won't run until it's fixed. // every Java program lives inside a class public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } } An algorithm becomes a program; a compiler turns Java source into runnable code. The Review Hub · AP Computer Science A Unit 1 TOPIC 1.2 Variables and Data Types A variable is a named memory location that holds a value of one type Java is STATICALLY TYPED: you declare a type, and the variable can only ever hold that type of value. int score = 100; double gpa = 3.75; boolean passed = true; int Whole numbers. No decimal point. 42, -7, 0 Stores 32-bit integers. double Decimal (real) numbers. Has a fractional part. 3.14, -0.5, 2.0 Stores 64-bit floating point. boolean A truth value. Only two options. true, false Used for conditions/logic. The three primitive types tested on the exam: int, double, boolean. The Review Hub · AP Computer Science A Unit 1 TOPIC 1.3 Expressions and Output Arithmetic operators + − * / % % is the REMAINDER (mod) operator. Precedence: * / % before + −. Use ( ) to force order. 17 % 5 → 2 13 / 4 → 3 Printing output System.out.print(x); prints with NO new line after System.out.println(x); prints, then moves to a new line + joins ("concatenates") strings. // string concatenation with + mixes text and values System.out.println("Total: " + count); // Total: 7 Mind operator precedence; println adds a new line, print doesn't. The Review Hub · AP Computer Science A Unit 1 TOPIC 1.4 Assignment Statements and Input = assigns right-to-left The = operator EVALUATES the right side, then stores that value in the variable on the left. int x = 5; x = x + 3; // x is now 8 — the old x (5) is read first Reading input with Scanner Scanner in = new Scanner(System.in); int n = in.nextInt(); nextInt(), nextDouble(), nextLine() Declare vs. assign DECLARE once (with a type): int count; ASSIGN as often as you like: count = 10; count = 11; = evaluates the right side first; a Scanner reads user input by type. The Review Hub · AP Computer Science A Unit 1 TOPIC 1.5 Casting and Range of Variables Integer division truncates int / int gives an int — the fraction is dropped (NOT rounded). 7 / 2 → 3 7.0 / 2 → 3.5 (double) 7 / 2 → 3.5 Casting between types (double) x int → double (widening, always safe) (int) 4.9 → 4 double → int TRUNCATES toward zero Cast binds tightly — cast before dividing. Range & overflow An int holds about ±2.1 billion (−2³¹ to 2³¹−1). Exceeding it OVERFLOWS and wraps to a wrong value. int/int truncates; cast to double to keep the fraction, cast to int to drop it. The Review Hub · AP Computer Science A Unit 1 TOPIC 1.6 Compound Assignment Operators Shorthand for "update a variable using itself" Each compound operator performs the arithmetic, then reassigns the result back into the variable. x += 3; is exactly x = x + 3; x += 5x = x + 5 x -= 5x = x - 5 x *= 5x = x * 5 x /= 5x = x / 5 x %= 5x = x % 5 Increment & decrement x++; // add 1 x--; // subtract 1 Very common as loop counters. x++ is shorthand for x = x + 1. +=, -=, *=, /=, %= update a variable in place; ++ / -- change it by one. The Review Hub · AP Computer Science A Unit 1 TOPIC 1.7 API and Libraries What an API is An Application Program Interface (API) documents the classes and methods a library provides, and how to call them. A LIBRARY = reusable prewritten code. Why it matters on the exam You don't memorize every method — you READ the API to find the right one and its parameters & return type. The AP Java Quick Reference is provided. // reading a method signature from the API tells you how to call it int length() // takes nothing, returns an int String substring(int from, int to) // two int params An API documents a library's methods — read it to learn parameters and return types. The Review Hub · AP Computer Science A Unit 1 TOPIC 1.8 Documentation with Comments // single-line comment — to the end of the line /* block comment spanning multiple lines */ /** Javadoc comment — documents a method */ // the compiler ignores all comments Why comment? Explain intent for human readers. Comments never affect execution. Preconditions & postconditions PRECONDITION: what must be true before. POSTCONDITION: what's true after it runs. Comments (//, /* */, /** */) are for humans — the compiler ignores them. The Review Hub · AP Computer Science A Unit 1 TOPIC 1.9 Method Signatures int max(int a, int b) return type name parameter list (types + names) Signature = name + parameters The signature is what you need to CALL a method: its name and the ordered list of parameter types. Arguments must match the parameter types. Parameters vs. arguments PARAMETER: the placeholder in the method definition (int a). ARGUMENT: the actual value you pass in when calling — max(3, 8). A method signature = name + parameter types; arguments must match in order and type. The Review Hub · AP Computer Science A Unit 1 TOPIC 1.10 Calling Class (Static) Methods Static methods belong to the CLASS, not an object Call them on the class name — no object needed. Format: ClassName.methodName(arguments) int big = Math.max(3, 8); double r = Math.sqrt(16); // the receiver is the CLASS name Math.abs(-5) → 5 Integer.parseInt("42") → 42 A method that returns a value can be used anywhere that value type is valid. Void vs. returning methods A void method does an action but gives back no value (e.g. println). A non-void method RETURNS a value you can store or use in an expression. Match the return type to how you use it. Call static methods on the class name: ClassName.method(args). The Review Hub · AP Computer Science A Unit 1 TOPIC 1.11 The Math Class // the four Math methods on the AP Java Quick Reference Math.abs(x) absolute value Math.pow(b, e) b to the power e (returns double) Math.sqrt(x) square root (returns double) Math.random() double in [0.0, 1.0) Random int in a range — a classic exam formula (int)(Math.random() * (max - min + 1)) + min e.g. a fair die (1–6): (int)(Math.random() * 6) + 1. The (int) cast truncates to a whole number. Know abs, pow, sqrt, random — and the random-int-in-range formula. The Review Hub · AP Computer Science A Unit 1 TOPIC 1.12 Objects: Instances of Classes Class vs. object A CLASS is a blueprint/template that defines state (data) and behavior (methods). An OBJECT is one specific INSTANCE built from that blueprint. Many objects can come from one class. Analogy: cookie cutter The CLASS is the cookie cutter. Each OBJECT is a cookie it stamps out. Cookies share a shape but can differ in their own attribute values. String is a class; "hi" is an object. Reference types Objects are REFERENCE types: the variable stores a reference (address), not the object itself. A class is the blueprint; an object is one instance built from it. The Review Hub · AP Computer Science A Unit 1 TOPIC 1.13 Object Creation (Instantiation) Robot r = new Robot(5, 10); type new keyword constructor call + arguments The new keyword new allocates memory for the object and runs its CONSTRUCTOR to set up the initial state. It returns a reference to the new object. null & aliasing A reference not yet pointing at an object is null. Using it → NullPointerException. Two variables can ALIAS the same object, so a change through one shows in both. new ClassName(args) allocates the object and runs its constructor. The Review Hub · AP Computer Science A Unit 1 TOPIC 1.14 Calling Instance Methods Instance methods are called ON an object Format: objectReference.methodName(arguments). The object is the RECEIVER of the call. String s = "hello"; int n = s.length(); // n = 5 // receiver . method ( args ) account.deposit(50); account.getBalance(); Different objects keep their own state, so the same call can give different results. Instance vs. static — the difference STATIC: called on the class Math.sqrt(9) INSTANCE: called on an object myStr.length() Instance methods can use the object's fields. Instance methods use object.method(args) — the object is the receiver. The Review Hub · AP Computer Science A Unit 1 TOPIC 1.15 String Manipulation String s = "COMPUTER"; // indices 0..7, length 8 s.length() → 8 s.substring(0, 4) → "COMP" (0 up to but NOT 4) s.indexOf("P") → 3 (-1 if not found) s.equals("computer") → false (case-sensitive) Zero-indexed & immutable First character is index 0; last is length() − 1. Strings never change. Compare with .equals, not == == compares references; .equals compares the actual characters. Strings are zero-indexed and immutable; compare with .equals, and substring excludes the end. The Review Hub · AP Computer Science A Unit 1
1 / 15

How to use the visual review

Spend 30 seconds per slide before clicking next. Look at the code, then ask yourself: "Could I predict this output or write this method call from memory?"

Use the fullscreen button () on desktop for the best experience. Use arrow keys to navigate. Tap "Show all slides" to jump around.

This is great for review the night before the exam — fast, visual, and covers every idea you need to recognize in Unit 1.