AP Computer Science A Unit 1 ReviewUsing Objects and Methods

Verified for the 2027 examCompiled by AP educators
Pep mascot
Upgrade your Fiveable account to print any study guide

Download study guides as beautiful PDFs See example

Print or share PDFs with your students

Always prints our latest, updated content

Mark up and annotate as you study

Click below to go to billing portal → update your plan → choose Yearly→ and select "Fiveable Share Plan". Only pay the difference

Plan is open to all students, teachers, parents, etc
Pep mascot
Upgrade your Fiveable account to export vocabulary

Download study guides as beautiful PDFs See example

Print or share PDFs with your students

Always prints our latest, updated content

Mark up and annotate as you study

Plan is open to all students, teachers, parents, etc

AP Computer Science A Unit 1, Using Objects and Methods, covers 15 topics worth 15-25% of the AP exam, introducing sorting algorithms, java objects, and the core Java syntax you need to write real programs. You'll work through variables, data types, casting, expressions, and compound assignment operators, then move into object creation, instantiation, and calling instance methods. AP CSA rounds this out with string manipulation via the String class and Math class methods, plus APIs and documentation.

unit 1 review

AP CSA Unit 1, Using Objects and Methods, is your introduction to Java, covering how to store data in variables, write arithmetic expressions, and use objects and the methods that come with them. The single biggest idea is that Java code works with two kinds of data, primitive values (int, double, boolean) and object references, and you interact with objects by calling methods on them with the dot operator. Unit 1 makes up 15-25% of the AP exam, the largest weight range of any unit, and everything else in the course is built on top of it.

What this unit covers

How programs work: algorithms, compilers, and errors

  • An algorithm is a step-by-step process for solving a problem, and sequencing means steps run one at a time, in order. Before you write any Java, you should be able to describe an algorithm in plain language or a diagram.
  • You write code in an IDE, and a compiler checks it for errors before the program can run. The compiler catches some mistakes, but not all of them.
  • Three error types to keep straight. A syntax error breaks Java's grammar rules and the compiler catches it. A logic error compiles fine but produces wrong output, and you only find it by testing. A run-time error crashes the program while it runs (like ArithmeticException from dividing an int by zero).
  • Comments (//, /* */, and Javadoc /** */) document code for humans. The compiler ignores them. Preconditions and postconditions describe what must be true before and after a method runs.

Variables, expressions, and the int vs. double trap

  • The three primitive types in this course are int (integers), double (real numbers), and boolean (true or false). A variable is a named storage location whose value can change while the program runs.
  • Arithmetic uses +, -, *, /, and % (remainder). The rule that decides half the answers in this unit: two ints produce an int, so 7 / 2 is 3, not 3.5. If at least one operand is a double, the result is a double.
  • Casting converts between types. (int) truncates the decimal part (it chops, it does not round), while ints widen to doubles automatically. To round a non-negative double, use (int)(x + 0.5); for negatives, (int)(x - 0.5).
  • Ints live in 4 bytes of memory, so they max out at Integer.MAX_VALUE and bottom out at Integer.MIN_VALUE. Going past either causes overflow. Doubles have limited precision too, which causes round-off errors.
  • Compound assignment operators (+=, -=, *=, /=, %=) do the operation and the assignment in one step. x++ and x-- add or subtract 1.
  • System.out.println prints and moves to a new line; System.out.print prints and stays on the same line. Escape sequences \", \\, and \n let you put special characters inside string literals.

Classes, objects, and constructors

  • A class is the blueprint; an object is one specific instance built from that blueprint. A Car class describes what every car has and does, while myCar is one actual car with its own attribute values.
  • A reference variable doesn't hold the object itself, it holds the object's memory address. If there's no object, the variable holds null.
  • You create objects with new plus a constructor call, like new Car("red", 2024). Constructors share the class's name, and their signature is the name plus the ordered list of parameter types.
  • Constructors can be overloaded, meaning a class has several constructors with different parameter lists. You pick which one runs by matching your arguments to a signature in number, order, and type.
  • Related classes can share a superclass that holds their common attributes and behaviors, and subclasses extend it. That's a class hierarchy, and you'll see much more of it later.

Methods: reading signatures and calling them correctly

  • A method is a named block of code that runs only when called. Procedural abstraction means you can use a method knowing what it does without knowing how it's written, the same way you drive a car without understanding the engine.
  • Parameters are the variables in a method's header; arguments are the actual values you pass in when calling. Arguments must match the parameters in number, order, and compatible type.
  • A void method returns nothing, so it stands alone as a statement. A non-void method returns a value you should store in a variable or use inside an expression, otherwise the result vanishes.
  • Instance methods are called on an object with the dot operator (myCar.getColor()). Calling any method on a null reference throws a NullPointerException.
  • Class (static) methods belong to the class itself, so you call them with the class name (Math.sqrt(25)). The static keyword in the header is the giveaway.
  • APIs and libraries document existing classes so you can use them without writing them. Attributes are the data; behaviors are the methods.

The Math and String classes

  • The Math class lives in java.lang (available by default) and contains only static methods: Math.abs, Math.pow, Math.sqrt, and Math.random(), which returns a double from 0 up to but not including 1.
  • The random-range formula is everywhere on the exam. (int)(Math.random() * range) + min gives a random int from min to min + range - 1.
  • Strings are objects representing character sequences, and they are immutable. No String method ever changes the original; methods like substring return a brand new String.
  • String indices run from 0 to length() - 1. Going outside that range throws a StringIndexOutOfBoundsException.
  • Required String methods include length(), substring(from, to) (includes index from, excludes index to), indexOf(str) (returns -1 if not found), equals(other), and compareTo(other). Use equals to compare String contents, never ==.

Unit 1, Using Objects and Methods at a glance

Topic clusterCore ideaMust-know detailClassic gotcha
Program basics (1.1, 1.8)Algorithms are ordered steps; compilers catch syntax errorsSyntax vs. logic vs. run-time errorsLogic errors compile cleanly
Primitives and expressions (1.2-1.4)int, double, boolean store values; = assignsint / int gives an int result7 / 2 is 3, not 3.5
Casting and limits (1.5)Convert types; memory limits values(int) truncates; overflow at Integer.MAX_VALUE(int) 3.9 is 3, not 4
Compound operators (1.6)Shorthand for operate-then-assign+=, -=, *=, /=, %=, ++, --x++ adds 1; it's not just decoration
Objects and constructors (1.12, 1.13)Class is the blueprint; object is the instancenew + constructor; match signature by parameter typesReference holds an address, possibly null
Calling methods (1.9, 1.10, 1.14)Static methods use the class name; instance methods use the objectvoid vs. return values; argument order mattersMethod call on null throws NullPointerException
Math class (1.11)All static, all in java.langMath.random() gives [0, 1)Random range formula: (int)(Math.random()*range)+min
Strings (1.15)Immutable character sequences, indexed from 0substring(from, to) excludes index toCompare with equals, not ==

Why Unit 1, Using Objects and Methods matters in AP CSA

Unit 1 carries the heaviest exam weight in the course and supplies the vocabulary for every other unit. AP CSA is built around modeling real-world things as objects, and this unit is where you learn what an object is and how to talk to one.

  • The class-object relationship introduced here (blueprint vs. instance) is the foundation of object-oriented programming, the course's central idea.
  • Procedural abstraction, using a method based on its signature and documentation without reading its code, is the skill behind every FRQ, where you call methods from classes you didn't write.
  • The int vs. double evaluation rules and casting behavior show up inside nearly every code-tracing question for the rest of the year.
  • Strings and the dot operator pattern (object.method(arguments)) are the muscle memory you need before loops, classes, and ArrayLists make any sense.

How this unit connects across the course

  • The boolean type and expression evaluation you learn here become the conditions inside if statements and loops in Selection and Iteration (Unit 2). String traversal with length(), substring, and indexOf pairs with loops there to process text character by character.
  • In Class Creation (Unit 3), you flip from using classes to writing them. Constructors, method signatures, parameters, return types, and instance vs. static methods all reappear, except now you're the author. The superclass and subclass hierarchy idea from Topic 1.12 pays off there too.
  • Data Collections (Unit 4) stores object references in arrays, 2D arrays, and ArrayLists. The reference-vs-primitive distinction and zero-based indexing from Strings transfer directly, including the out-of-bounds exception pattern.

Key syntax and algorithms

  • int x = 5; double y = 2.5; boolean flag = true; declares and initializes the three primitive types.
  • System.out.println(...) vs. System.out.print(...) prints with or without a trailing newline.
  • % (remainder operator) gives the leftover after integer division; x % 2 == 0 tests for even numbers and x % 10 grabs the last digit.
  • (int) and (double) casts convert between numeric types; (int) truncates toward zero.
  • (int)(x + 0.5) rounds a non-negative double to the nearest integer; use (int)(x - 0.5) for negatives.
  • x += 3; and friends (-=, *=, /=, %=) operate and assign in one statement; x++ and x-- adjust by 1.
  • ClassName var = new ClassName(args); declares a reference variable and instantiates an object with a constructor.
  • objectName.methodName(args) calls an instance method; ClassName.methodName(args) calls a static method.
  • Math.abs(x), Math.pow(base, exp), Math.sqrt(x), Math.random() are the four required Math methods.
  • (int)(Math.random() * range) + min generates a random integer from min through min + range - 1.
  • str.length(), str.substring(from, to), str.substring(from), str.indexOf(other), str.equals(other), str.compareTo(other) are the required String methods; substring(i, i + 1) extracts a single character as a String.

Unit 1, Using Objects and Methods on the AP exam

Unit 1 is weighted at 15-25% of the exam, the widest and heaviest range in the course. On the multiple-choice section, this content appears mostly as code analysis. You'll determine what a code segment prints, evaluate an arithmetic expression where int division or casting changes the answer, trace what value a variable holds after a series of assignments, or predict the result of String method calls (substring boundaries are a favorite). Expect questions that hand you a class's documentation or method signatures and ask which call is valid, or what a call returns, testing whether you can read an API without seeing the implementation.

On the free-response section, Unit 1 skills are baked into everything. Every FRQ requires you to call methods on objects you're given, pass arguments that match parameter lists, store and use return values, and build Strings or numeric results correctly. The Java Quick Reference provided on the exam lists the required Math and String methods, but you need to know what they do and their exact behavior (like substring excluding the to index) cold, because the reference won't explain the gotchas.

Essential questions

  • Why does Java distinguish between primitive values and object references, and how does that change what a variable actually stores?
  • How can a programmer use a class effectively without ever seeing the code inside its methods?
  • Why do computers produce "wrong" answers like 7 / 2 = 3 or integer overflow, and how do you write code that accounts for those limits?
  • What makes an object different from the class that defines it?

Key terms to know

  • Object: a specific instance of a class with its own attribute values.
  • Class: the blueprint defining the attributes and behaviors that its objects share.
  • Constructor: a special block of code, named the same as the class, that creates and initializes an object when called with new.
  • Method signature: a method's name plus its ordered list of parameter types, used to identify which method or constructor is being called.
  • Parameter vs. argument: a parameter is the variable in the method header; an argument is the actual value passed in the call.
  • Procedural abstraction: using a method based on what it does without knowing how it is implemented.
  • Reference type: a data type whose variables hold an object's memory address (or null) rather than the value itself.
  • null: a special literal meaning a reference variable points to no object; calling a method on it throws a NullPointerException.
  • Static (class) method: a method belonging to the class itself, called with the class name and the dot operator, like Math.sqrt.
  • Immutable: unable to be changed after creation; String methods return new Strings instead of modifying the original.
  • Truncation: what (int) casting does to a double, dropping everything after the decimal point without rounding.
  • Integer overflow: the result of an int expression going beyond Integer.MAX_VALUE or below Integer.MIN_VALUE.
  • Compound assignment operator: shorthand like += that performs an operation and stores the result back in the variable in one step.
  • API: documentation specifying a class's attributes and behaviors so programmers can use it without reading its source code.

Common mix-ups

  • Integer division vs. real division: 7 / 2 evaluates to 3 because both operands are ints. Write 7 / 2.0 or (double) 7 / 2 to get 3.5. This single rule answers a surprising number of multiple-choice questions.
  • Casting vs. rounding: (int) 3.9 is 3, not 4. Casting truncates. Rounding requires the (int)(x + 0.5) pattern.
  • == vs. equals for Strings: == checks whether two references point to the same object; equals checks whether the contents match. Always use equals to compare String values.
  • substring boundaries: substring(2, 5) includes index 2 but excludes index 5, returning 3 characters. And indexOf returns -1 (not an exception) when the substring isn't found.

Frequently Asked Questions

What topics are covered in AP CSA Unit 1?

AP CSA Unit 1 covers 15 topics that build the foundation of Java programming: algorithms and compilers, variables and data types, expressions and output, assignment statements and input, casting, compound assignment operators, APIs and libraries, documentation with comments, method signatures, calling class methods, the Math class, objects and instantiation, calling instance methods, and String manipulation. See the full topic list at AP CSA Unit 1.

How much of the AP CSA exam is Unit 1?

Unit 1 makes up 15-25% of the AP CSA exam, making it one of the most heavily weighted units. It covers core Java concepts like variables, data types, expressions, object creation, and String and Math class methods. A strong grasp of this unit directly supports your performance across the rest of the exam.

What's on the AP CSA Unit 1 progress check (MCQ and FRQ)?

The AP CSA Unit 1 progress check in AP Classroom includes both MCQ and FRQ parts drawn from the unit's 15 topics. MCQ questions test variables, data types, casting, expressions, compound assignment operators, and method signatures. FRQ questions focus on object creation, calling instance methods, and String manipulation. Reviewing those topics before attempting the progress check is the most efficient prep. Practice with aligned questions at AP CSA Unit 1.

How do I practice AP CSA Unit 1 FRQs?

AP CSA Unit 1 FRQs typically ask you to write or trace code involving object creation, calling instance methods, and String manipulation. To practice, write short Java programs that instantiate objects, call Math and String class methods, and use variables with correct data types. Check your output against expected results, then review any casting or method signature errors. Find practice FRQs at AP CSA Unit 1.

Where can I find AP CSA Unit 1 practice questions?

The best place to find AP CSA Unit 1 practice questions, including multiple-choice and practice test sets, is AP CSA Unit 1. That page has MCQ practice covering variables, data types, expressions, casting, compound assignment operators, APIs, and object instantiation, so you can test each topic before moving on. Mixing MCQ practice with short coding exercises on String and Math methods gives you the most complete prep.

How should I study AP CSA Unit 1?

Start with variables and data types, since every other topic in Unit 1 builds on them. Then work through expressions, assignment statements, and casting before moving to method signatures and APIs. Once those feel solid, practice calling Math and String class methods, then move to object creation and calling instance methods. Write small Java programs for each topic rather than just reading. Use the progress check MCQ to spot gaps, and revisit any topic where casting or method calls trip you up. Full topic guides are at AP CSA Unit 1.