AP CSA · Unit 1

Java Primitives Practice Lab

Sort real-world data, explore casting, learn the vocabulary, understand %, then prove it with 20 arithmetic questions.

Activity 1 · 30-Second Sprint

Type Detective

The value is hidden. Pick the primitive type before time runs out — get it right and it flashes by fast, get it wrong and it holds for two seconds so you can study it.

30Seconds
0Solved
0Streak
0Best

Time's up!

You solved 0 case files.

Reference

The Eight Primitive Types

Java has exactly eight primitives. Everything else you'll ever use — String, arrays, ArrayList, any object — is a reference type, not a primitive.

Reference types (String, arrays, and every object) don't store the value directly — they store a pointer to where the real data lives. That's a topic for another day, but it's why String is not on this list of eight.

Widening & Narrowing

The Precision Lab

Going from int → double is automatic and safe. Going from double → int needs an explicit cast, and it costs you information.

Widening — always safe

int → double

Every int fits inside a double, so Java converts it automatically. No cast, nothing lost.

1int x = 7;
2double y = x; // y = 7.0

Java tacks on .0 and stops — the value doesn't change, only the box it lives in gets bigger.

Narrowing — needs a cast

double → int

A double can hold values int can't, so you must force the cast — and Java throws information away to make it fit.

1double value = 9.86;
2int x = (int) value; // x = 9
3int x = (int) Math.round(value); // x = 10

(int) always truncates toward zero — it doesn't round. That's why line 2 gives 9, not 10. Line 3 needs its own (int) because Math.round(double) actually returns a long.

Vocabulary

Flip Cards

Tap a card to flip it. Read the term, guess the definition, then check yourself.

One More Operator

What Does % Actually Do?

% is the modulus (or "mod") operator. It doesn't divide — it tells you the remainder left over after division. 17 % 5 asks "how many are left over after fitting as many 5s as possible into 17?" 5 fits three times (15), leaving 2. So 17 % 5 is 2.

It's one of the most useful tools in programming for anything that wraps around or repeats in a cycle: checking even/odd, cycling through a list, formatting a clock, and more.

10 % 3 → 13 fits into 10 three times (9), 1 left over.
n % 2 == 0Classic even check — if there's nothing left over after dividing by 2, it's even.
(hour + 1) % 12Clock math — after 11, wrap back around to 0.
-7 % 3 → -1Java keeps the sign of the first number — negatives can trip you up!

Activity 2 · Graded

20 Questions: Arithmetic & Casting

Every question is visible at once. Answer in any order, as many times as you need — a field turns green the moment it's right. Get all 20 green to earn your certificate below.

0 / 20 correct