Skip to main content
← AP CSA Study Guide

Unit 1 · Foundational

Primitive Types and Expressions

The arithmetic layer everything else sits on. Most of this unit is one rule with wide consequences: Java decides the type of an expression before it decides the value, and integer division discards the remainder rather than rounding.

What a strong answer looks like

A strong Unit 1 answer states the type of each subexpression before its value, and names integer division explicitly wherever it applies.

Topics in this unit

1

Primitive Expressions

Practice this topic →

Know

Java evaluates operators by precedence, not left to right, and the type of the result is determined by the operand types. Mixing an int with a double promotes the result to double.

Apply

Evaluate an expression by resolving parentheses, then multiplication and division, then addition and subtraction, recording the type at each step.

Watch out

Assuming every division keeps its decimal part. Two ints divide to an int no matter what the surrounding expression looks like.

Study move

Trace five expressions that mix int, double, and parentheses, writing the type beside every intermediate value.

2

Integer Division and Mod

Practice this topic →

Know

Integer division truncates toward zero rather than rounding, and modulus returns the remainder. Together they split a number into complete groups and a leftover.

Apply

Use division for how many whole groups fit and modulus for what remains, as when converting minutes into hours and minutes.

Watch out

Rounding instead of truncating, and forgetting that a negative operand changes the sign of the remainder.

Study move

Convert several totals of minutes into hours and leftover minutes using only division and modulus.

3

Casting and Math.random

Practice this topic →

Know

A cast changes how a value is interpreted, and where the cast sits changes the result. Scaling a random value requires casting after multiplying, not before.

Apply

Build a random range by multiplying first, casting to int second, and adding the lower bound last.

Watch out

Casting too early throws away the fractional part that the scaling needed, collapsing the range.

Study move

Write an expression producing a random index for an array of length n, then state its minimum and maximum.

4

String Concatenation

Practice this topic →

Know

The plus operator concatenates when either operand is a String, and evaluates left to right. That order decides whether numbers are added first or appended as text.

Apply

Read a mixed expression left to right, switching to concatenation from the first String onward.

Watch out

An expression beginning with two ints adds them; the same operands after a String are appended as digits.

Study move

Compare the output of an expression with and without parentheses around its numeric part.

Emphasized in this unit

Connections and techniques that receive extra attention in this unit.

  • Naming the type of every intermediate value before its number
  • Reading operator precedence rather than assuming left-to-right evaluation
  • Treating integer division as the default rather than the exception

Varies by course

Related topics some schools attach to this unit and others leave out. Covered on request rather than assumed.

  • Bitwise operators. Taught in some classes for interest; not on the AP CSA exam.
  • char arithmetic. Occasionally introduced early, though the exam keeps it light.

Mastery checklist

  • State the type of an expression mixing int and double.
  • Compute integer division and modulus, including with a negative operand.
  • Place a cast correctly when scaling a random value.
  • Predict the output of a concatenation that mixes numbers and text.

Check yourself

  • Why does 7 / 2 give 3 while 7.0 / 2 gives 3.5?
  • Where must the cast go when building a random number in a range, and why?
  • How does the position of the first String change a concatenation result?

Modeling drill

Write a single expression that converts a total number of seconds into whole minutes and leftover seconds, then trace it for 0, 59, and 60.

Primitive typePrecedenceInteger divisionModulusCastConcatenation