AP® Computer Science A
Practice
AP® Computer Science A

AP® Computer Science A Unit 1 Cheat Sheet: Using Objects and Methods

This AP CSA Unit 1 cheat sheet covers the building blocks of every Java program you’ll write on the exam: variables and types, expressions, casting, method calls, the Math class, objects, and String methods. Using Objects and Methods makes up 15–25% of the AP® Computer Science A exam. Use the Simple version to learn the core or the Ultimate version for full detail.

Practice AP® Computer Science A Unit 1 questions on Albert

What’s on the AP CSA Unit 1 Cheat Sheet?

Both versions share eight cards: programs, variables, and types; expressions and output; casting and compound assignment; APIs, comments, and method signatures; the Math class; objects and instantiation; instance methods and Strings; and a final card on code tracing and exam strategy.

You get the Java Quick Reference on exam day, so the sheet doesn’t just repeat method names. It shows how those methods behave and where students lose points: integer division, cast placement, substring end indexes, == vs. .equals(), and random-number ranges.

The Simple version gives you the essentials in short lines with worked examples. It’s the right place to start if Java is new to you.

The Ultimate version adds more tracing tables, overflow and round-off, escape sequences, call by value, aliasing diagrams, compareTo, and a full table of Unit 1 traps. It’s built for the weeks just before the exam.

AP CSA Unit 1 at a Glance

The College Board’s AP® Computer Science A course page and CED split Unit 1 into 15 topics.

TopicNameFocus
1.1Introduction to Algorithms, Programming, and CompilersAlgorithms, compiling, error types
1.2Variables and Data Typesint, double, boolean, reference types
1.3Expressions and OutputArithmetic, integer division, %, print vs. println
1.4Assignment Statements and InputHow = works, reading input
1.5Casting and Range of Variables(int) and (double) casts, overflow, round-off
1.6Compound Assignment Operators+=, -=, *=, /=, %=, ++, —
1.7Application Program Interface (API) and LibrariesUsing prewritten classes
1.8Documentation with CommentsComments, preconditions, postconditions
1.9Method SignaturesParameters, return types, overloading
1.10Calling Class MethodsStatic method calls
1.11Math Classabs, pow, sqrt, random
1.12Objects: Instances of ClassesClass vs. object
1.13Object Creation and Storage (Instantiation)new, constructors, references, null
1.14Calling Instance MethodsDot notation, NullPointerException
1.15String Manipulationlength, substring, indexOf, equals, compareTo

Unit 1 is 15–25% of the exam, but its skills show up almost everywhere. Every free-response question uses variables, expressions, and method calls, and String methods appear constantly in multiple-choice tracing questions.

Key Concepts in Unit 1: Using Objects and Methods

Types, Expressions, and Integer Division

The AP exam uses three primitive types: int for whole numbers, double for decimals, and boolean for true and false. Everything else, including String, is a reference type that stores the address of an object.

The rule that costs the most points is integer division. When both operands are ints, Java drops the decimal: 7 / 2 is 3, not 3.5. If either operand is a double, the result is a double. The modulus operator % gives the remainder, which makes it useful for checking even numbers (n % 2 == 0) or pulling off the last digit (n % 10).

Worked example: What does 1 / 2 * 4.0 evaluate to? Java works left to right at the same precedence level. First 1 / 2 is integer division, giving 0. Then 0 * 4.0 gives 0.0. The answer is 0.0, not 2.0.

Exam tip: When you trace an expression, write the type next to every intermediate value. The moment you see int / int, stop and truncate.

Casting, Range, and Compound Assignment

Java converts int to double automatically (widening). Going the other way needs an explicit cast, and the cast truncates: (int) 3.99 is 3. To round a positive number to the nearest int, add 0.5 before casting: (int)(x + 0.5).

Cast placement matters. A cast applies only to the value right after it, so (double) 7 / 2 is 3.5 (7.0 / 2), while (double)(7 / 2) is 3.0 (the division already happened).

An int holds values between Integer.MIN_VALUE and Integer.MAX_VALUE, about ±2.1 billion. Going past the limit causes overflow: the value wraps around with no error. Doubles have a different problem. They store decimals approximately, so 0.1 + 0.2 isn’t exactly 0.3.

Worked example: After int x = 10; x += 5; x /= 4; x %= 2;, what is x? 10 + 5 = 15, then 15 / 4 = 3 (integer division), then 3 % 2 = 1. The answer is 1.

Exam tip: Compound operators follow the same type rules as the long form. x /= 4 on an int still truncates.

Methods: Signatures, Parameters, and Static Calls

A method signature is its name plus its parameter list. In public static double area(double r), the return type is double and there’s one double parameter. A void method returns nothing; a non-void method must return a value of its declared type.

Parameters are the variables in the method header; arguments are the values you pass when you call it. Arguments must match the parameters in number, order, and type. Java passes arguments by value, so if a method changes a primitive parameter, the caller’s variable stays the same.

Static (class) methods are called on the class name, like Math.sqrt(16), with no object needed. Overloaded methods share a name but have different parameter lists. A different return type alone doesn’t count as overloading.

Exam tip: Read preconditions on free-response questions carefully. They tell you what you can assume, so you don’t need to write code to check those conditions.

The Math Class and Random Numbers

The Quick Reference lists Math.abs, Math.pow, Math.sqrt, and Math.random. Remember that pow and sqrt always return doubles, so storing their results in an int needs a cast.

Math.random() returns a double from 0.0 up to, but not including, 1.0. To get a random int from min to max, use (int)(Math.random() * range) + min, where range = max − min + 1.

Worked example: To simulate a six-sided die, range = 6 − 1 + 1 = 6, so the code is (int)(Math.random() * 6) + 1. Check it: the smallest product is 0.0, which gives 0 + 1 = 1. The largest is just under 6.0, which casts to 5, giving 5 + 1 = 6.

Exam tip: (int) Math.random() * 6 is always 0. The cast turns the random value into 0 before the multiplication. Put parentheses around the whole product.

Objects, References, and Strings

A class is a blueprint; an object is one instance of it. You create objects with new and a constructor: Dog d = new Dog(“Rex”, 3);. Just declaring Dog d; creates no object. A reference variable holds the object’s address, so Dog d2 = d; makes both variables point to the same object (aliasing). Calling a method on a null reference throws a NullPointerException.

Strings are objects, and they’re immutable: methods like substring return a new String instead of changing the original. Indexes run from 0 to length() − 1. In substring(a, b), the character at b is not included, and the result has b − a characters.

Worked example: With String s = “APCSA”;, s.substring(1, 3) is “PC” (indexes 1 and 2), s.indexOf(“CS”) is 2, and s.indexOf(“Z”) is −1.

Exam tip: Compare String contents with .equals(). The == operator only checks whether two references point to the same object.

How Unit 1 Shows Up on the Exam

The exam has two 90-minute sections. Section I has 42 multiple-choice questions (55% of the score); Section II has four free-response questions (45%): methods and control structures, class design, data analysis with ArrayList, and a 2D array. You get the Java Quick Reference for both sections.

Unit 1 shows up in multiple-choice questions that ask you to trace a few lines of code and pick the output, find the line that won’t compile, or predict the value of an expression. Integer division, casting, and String methods are the most common targets. On the free-response section, Unit 1 skills are the tools you use everywhere: calling methods correctly, using return values, building Strings with substring, and generating numbers with Math methods.

Common Mistakes in Unit 1

  • Forgetting integer division. 5 / 2 is 2. Cast one operand to double if you need the decimal.
  • Placing the cast wrong. (int) Math.random() * 10 is always 0. Cast the whole expression.
  • Including the end index in substring. substring(1, 3) returns two characters, at indexes 1 and 2.
  • Comparing Strings with ==. Use .equals() to compare contents.
  • Ignoring a return value. s.substring(1); on its own does nothing, because Strings are immutable. Write s = s.substring(1);

Frequently Asked Questions

Can I use this cheat sheet on the AP CSA exam?

No. The only reference allowed is the official Java Quick Reference, which is built into the exam. Use this sheet to study and to check your tracing on practice problems.

Should I start with the Simple or the Ultimate version?

Start with the Simple AP CSA Unit 1 cheat sheet if you’re new to Java or need a fast refresher. Move to Ultimate once you can trace the Simple examples without mistakes.

What’s on the Java Quick Reference for Unit 1?

It lists the String and Math methods you’re expected to use, along with Integer, Double, ArrayList, and other classes from later units. It gives method names and short descriptions, but it won’t warn you about traps like substring’s exclusive end index.

What’s the hardest part of Unit 1?

For most students it’s tracing mixed-type expressions: integer division, cast placement, and String concatenation all happen in a single line. Use the AP CSA Unit 1 cheat sheet tables to drill those cases until you can predict each result instantly.

How much of the exam is Unit 1?

Unit 1 is weighted at 15–25%. Because every later unit builds on it, mastering it pays off well beyond that share.

Ready to practice? Try Albert free.

Build real confidence with thousands of adaptive practice questions across AP®, SAT®, ACT®, and core subjects — aligned to what you’re studying right now.

Practice for AP® Computer Science A