Skip to main content

Unit 1

15–25% of exam

Using 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 sheet

Free-response questions on this unit

Write your own answer, then score it with the rubric or with AI.

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
  • int division 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.

  • AP Computer Science A Unit 1 Review | Objects & Methods (AP CSA Exam Prep)

    Goldie's Math EmporiumWatch on YouTube (opens in a new tab)

  • 2026 AP Computer Science A Exam Review - CRASH COURSE for Unit 1: Using Objects and Methods

    Tim Gallagher Computer ScienceWatch on YouTube (opens in a new tab)

  • AP CSA Unit 1 Full Review | NEW 2026 |

    Scratch SkillsWatch on YouTube (opens in a new tab)

  • AP Computer Science A - Unit 2: Using Objects

    Bill BarnumWatch on YouTube (opens in a new tab)

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
  • AP Computer Science A - Topic 1.1: Introduction to Algorithms, Programs, and Compilers

    Tim Gallagher Computer ScienceWatch on YouTube (opens in a new tab)

  • Compilation, Execution, and Errors

    CodeHSWatch on YouTube (opens in a new tab)

  • AP CSA Using Objects and Methods – Welcome to Java

    Goldie's Math EmporiumWatch on YouTube (opens in a new tab)

  • Creating, Compiling, and Executing a Java Program

    Neso AcademyWatch on YouTube (opens in a new tab)

  • Introduction to Algorithms

    CodeHSWatch on YouTube (opens in a new tab)

Read the review notes: 1.1 Introduction to Algorithms, Programming, and Compilers

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
  • int
  • double
  • boolean
  • variable
  • AP Computer Science A - Topic 1.2 – Variables and DataTypes

    Tim Gallagher Computer ScienceWatch on YouTube (opens in a new tab)

  • Variables and Primitive Data Types (Part 1)

    CodeHSWatch on YouTube (opens in a new tab)

  • Primitive and Reference (Object) Types in Memory (Java Tutorial)

    Bill BarnumWatch on YouTube (opens in a new tab)

  • Variables and Primitive Data Types (Part 2)

    CodeHSWatch on YouTube (opens in a new tab)

  • Primitive Types and Reference Types in Java

    Neso AcademyWatch on YouTube (opens in a new tab)

Read the review notes: 1.2 Variables and Data Types

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
  • AP Computer Science A - Topic 1.3 - Part 1: Expressions and Output

    Tim Gallagher Computer ScienceWatch on YouTube (opens in a new tab)

  • int and double Division (Java Tutorial)

    Bill BarnumWatch on YouTube (opens in a new tab)

  • AP Java - Basic Math

    CodeHSWatch on YouTube (opens in a new tab)

  • AP Computer Science A - Topic 1.3 - Part 2: Expressions and Output

    Tim Gallagher Computer ScienceWatch on YouTube (opens in a new tab)

  • Java arithmetic is easy! 🧮

    Bro CodeWatch on YouTube (opens in a new tab)

  • Operator Precedence / Order Of Operation (Java Tutorial)

    Bill BarnumWatch on YouTube (opens in a new tab)

Read the review notes: 1.3 Expressions and Output

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
  • null
  • Scanner
  • AP Computer Science A - Topic 1.4 - Part 1: Assignment Statements and Input

    Tim Gallagher Computer ScienceWatch on YouTube (opens in a new tab)

  • Assignment Statements

    CodeHSWatch on YouTube (opens in a new tab)

  • Declaring and Initializing a Variable (Java Tutorial)

    Bill BarnumWatch on YouTube (opens in a new tab)

  • AP Computer Science A - Topic 1.4 - Part 2: Assignment Statements and Input

    Tim Gallagher Computer ScienceWatch on YouTube (opens in a new tab)

  • How to accept user input in Java ⌨️【8 minutes】

    Bro CodeWatch on YouTube (opens in a new tab)

Read the review notes: 1.4 Assignment Statements and Input

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
  • AP Computer Science A - Topic 1.5 - Part 1: Casting and Range of Variables

    Tim Gallagher Computer ScienceWatch on YouTube (opens in a new tab)

  • AP CSA Using Objects and Methods – Casting and Range of Variables

    Goldie's Math EmporiumWatch on YouTube (opens in a new tab)

  • Casting a Primitive and Overflow (Java Tutorial)

    Bill BarnumWatch on YouTube (opens in a new tab)

  • AP Computer Science A - Topic 1.5 - Part 2: Casting and Range of Variables

    Tim Gallagher Computer ScienceWatch on YouTube (opens in a new tab)

  • Casting in Java

    Neso AcademyWatch on YouTube (opens in a new tab)

Read the review notes: 1.5 Casting and Range of Variables

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 --
  • AP Computer Science A - Topic 1.6 - Compound Assignment Operators

    Tim Gallagher Computer ScienceWatch on YouTube (opens in a new tab)

  • Compound Assignment Operators

    CodeHSWatch on YouTube (opens in a new tab)

  • Arithmetic and Unary Operators (Java Tutorial)

    Bill BarnumWatch on YouTube (opens in a new tab)

  • Java Compound Operators - Combined Assignment Arithmetic Operator Examples - Java Tutorial

    AppficialWatch on YouTube (opens in a new tab)

Read the review notes: 1.6 Compound Assignment Operators

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
  • AP Computer Science A - Topic 1.7: Application Programming Interface (API) and Libraries

    Tim Gallagher Computer ScienceWatch on YouTube (opens in a new tab)

  • Application Program Interface and Libraries

    CodeHSWatch on YouTube (opens in a new tab)

  • Get an overview of the Java API documentation and how to use it

    IBM DeveloperWatch on YouTube (opens in a new tab)

  • Navigating an API

    CodeHSWatch on YouTube (opens in a new tab)

  • Imports & Packages | Java | Tutorial 38

    Giraffe AcademyWatch on YouTube (opens in a new tab)

Read the review notes: 1.7 Application Program Interface (API) and Libraries

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
Read the review notes: 1.8 Documentation with Comments

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
Read the review notes: 1.9 Method Signatures

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
  • AP Computer Science A - Topic 1.10: Calling Class Methods

    Tim Gallagher Computer ScienceWatch on YouTube (opens in a new tab)

  • Calling Class Methods

    CodeHSWatch on YouTube (opens in a new tab)

  • Static vs Non-Static Variables and Methods In Java - Full Simple Tutorial

    Coding with JohnWatch on YouTube (opens in a new tab)

  • Static Methods and Non Static Methods (Java Tutorial)*

    Bill BarnumWatch on YouTube (opens in a new tab)

Read the review notes: 1.10 Calling Class Methods

A few quick questions on this topic, with the answers explained.

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

  • Math class
  • Math.abs
  • Math.pow
  • Math.sqrt
  • Math.random
  • inclusive vs. exclusive
  • AP Computer Science A - Topic 1.11 - Part 1: Math Class

    Tim Gallagher Computer ScienceWatch on YouTube (opens in a new tab)

  • AP CSA Using Objects and Methods – Math Class

    Goldie's Math EmporiumWatch on YouTube (opens in a new tab)

  • Random Numbers With Math.random() (Java Tutorial)

    Bill BarnumWatch on YouTube (opens in a new tab)

  • AP Computer Science A - Topic 1.11 - Part 2: Math Class

    Tim Gallagher Computer ScienceWatch on YouTube (opens in a new tab)

  • Java Math class 📐【6 minutes】

    Bro CodeWatch on YouTube (opens in a new tab)

Read the review notes: 1.11 Math Class

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
Read the review notes: 1.12 Objects: Instances of Classes

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
  • AP Computer Science A - Topic 1.13: Object Creation and Storage

    Tim Gallagher Computer ScienceWatch on YouTube (opens in a new tab)

  • Object Creation and Storage Instantiation (Part 1)

    CodeHSWatch on YouTube (opens in a new tab)

  • What is null and a null pointer exception? (Java Tutorial)

    Bill BarnumWatch on YouTube (opens in a new tab)

  • Object Creation and Storage Instantiation (Part 2)

    CodeHSWatch on YouTube (opens in a new tab)

  • AP CS A Unit 2 Lesson 2 - Creating and Storing Objects (Instantiation)

    Jacob MacMillanWatch on YouTube (opens in a new tab)

Read the review notes: 1.13 Object Creation and Storage (Instantiation)

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
  • AP Computer Science A - Topic 1.14: Calling Instance Methods

    Tim Gallagher Computer ScienceWatch on YouTube (opens in a new tab)

  • Calling Instance Methods

    CodeHSWatch on YouTube (opens in a new tab)

  • AP CSA - Unit 2: Using Objects - Lesson 2: Calling a Void Method

    Goldie's Math EmporiumWatch on YouTube (opens in a new tab)

  • Null Pointer Exceptions In Java - What EXACTLY They Are and How to Fix Them

    Coding with JohnWatch on YouTube (opens in a new tab)

  • AP CSA - Unit 2: Using Objects - Lesson 4: Calling a Non-Void Method

    Goldie's Math EmporiumWatch on YouTube (opens in a new tab)

Read the review notes: 1.14 Calling Instance Methods

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
  • substring
  • indexOf
  • equals and compareTo
  • AP Computer Science A - Topic 1.15 - Part 1: String Manipulation

    Tim Gallagher Computer ScienceWatch on YouTube (opens in a new tab)

  • AP CSA Unit 1 String Methods (2025)

    PickcodeWatch on YouTube (opens in a new tab)

  • substring And length (Java String Methods)

    Bill BarnumWatch on YouTube (opens in a new tab)

  • AP Computer Science A - Topic 1.15 - Part 2: String Manipulation

    Tim Gallagher Computer ScienceWatch on YouTube (opens in a new tab)

  • AP Computer Science A - Topic 1.15 - Part 3: String Manipulation

    Tim Gallagher Computer ScienceWatch on YouTube (opens in a new tab)

  • Java Strings are Immutable - Here's What That Actually Means

    Coding with JohnWatch on YouTube (opens in a new tab)

Read the review notes: 1.15 String Manipulation

A few quick questions on this topic, with the answers explained.