AP Computer Science A · Study guide

Data Type Categories

Unit 1 · Using Objects and Methods · Topic 1.2

Data Type Categories

Two categories, one question: does the variable hold the value, or does it hold directions to the value?

1What a Data Type Actually Is

Essential knowledge 1.2.A.1

A data type is a set of values and a corresponding set of operations on those values. Data types can be categorized as either primitive or reference.

Two halves, and the second is the one that gets forgotten. A type is not just "what can be stored" — it is also "what can be done with it." Those arrive together and neither is optional.

TypeIts set of valuesIts set of operations
intWhole numbers in a fixed range+ - * / %, comparisons
doubleReal numbers+ - * /, comparisons
booleanExactly true and false&& || !
StringSequences of characterslength(), substring(), + to join
Why "and operations" is not filler

7 / 2 gives 3 for int and 3.5 for double. Same symbol, same-looking numbers, different result — because division is one of the operations the type defines. Choosing a type chooses the arithmetic that comes with it.

The learning objective

1.2.A — identify the most appropriate data type category for a particular specification. The word is category. You are sorting a requirement into primitive or reference before worrying about which exact type.

2The Two Categories

Essential knowledge 1.2.A.2 and 1.2.A.3

Primitive data types define the set of values and operations for numbers and Boolean values. A reference type is used to define objects that are not primitive types.

In this course the primitives are exactly three — int, double, boolean. Everything else you will meet is a reference type: String, arrays, ArrayList, and every class you or anyone else writes.

The sorting question

Is this a number or a true/false? If yes, primitive. If it is anything else — text, a collection, a thing with parts — reference. That single question resolves nearly every specification you will be handed.

3What the Variable Holds — Step by Step

The categories differ in one concrete way, and it is worth watching happen rather than memorizing. A bike shop tracks stock for one model. Four statements, four pictures.

int stock = 12;
String model = "Roadster";
stock = 9;
model = "Tourer";

A primitive variable is the value. The box labeled stock contains 12 — there is nothing else anywhere.

A reference variable holds a reference. The box labeled model contains @B1, which is directions to a String object living on the heap. The characters "Roadster" are never inside the variable.

Reassigning a primitive overwrites the value in place. The 12 is gone; a 9 sits where it was. No object anywhere is involved.

Step 4 is the one that matters

Reassigning a reference does not change the object it used to point at. @B1 still holds "Roadster", exactly as before — the variable simply points somewhere new. Compare with step 3, where the old value genuinely ceased to exist. Same word, "reassign"; two different events.

3.1 Reading the Four Steps as a Table

StepCategoryWhat changedWhat survived
1Primitivestock now holds 12—
2Referencemodel holds a reference; an object is created—
3PrimitiveThe 12 is replaced by 9Nothing — 12 is gone
4ReferenceThe arrow moves to a new object"Roadster", untouched at @B1

4Choosing the Category from a Specification

Exam wording rarely says "use a reference type." It describes a requirement and you sort it.

SpecificationCategoryBecause
How many frames are in stock at the Busan branchPrimitiveA whole-number count
The price of a service, to the centPrimitiveA real number
Whether the branch is open on SundayPrimitiveTrue or false
The model name printed on the frameReferenceText is an object, not a number
Every model the Daegu branch carriesReferenceA collection is an object
A customer, with a name and a phone numberReferenceA thing with parts — a class
Two specifications that catch people

"A phone number." It contains digits, so it looks numeric — but you never add phone numbers, and leading zeros matter. The operations you actually need are text operations, so the appropriate category is reference. The set of values is only half the decision; the set of operations decides it.

"A single character." Genuinely primitive in Java — but char is explicitly outside this course. In AP CS A a single character is handled as a String of length one, which is a reference type.

In scope for this course

The primitives here are int, double, boolean. Java's other five — long, short, byte, float, char — are outside the scope of the course and exam, so no question will require them.

5Check Yourself

Give both halves of the definition of a data type.

Response

A set of values, and a corresponding set of operations on those values. Naming only the values is half an answer — and it is the half that fails to explain why 7/2 behaves differently for int and double.

A shop stores whether each bike has been serviced this year. Which category?

Response

Primitive. The value is true or false, and Boolean values are one of the two things primitives cover in this course.

After step 4 above, what is stored at @B1?

Response

Still "Roadster". Reassigning model moved the reference to a new object; it did not reach back and alter the old one. Nothing about step 4 touched @B1.

Why is the list of every model a branch carries a reference type?

Response

Because a reference type defines objects that are not primitive types, and a collection is an object. It is neither a number nor a true/false, so it cannot be primitive — the variable will hold a reference to the collection rather than the collection itself.

6Summary

IdeaWhat to remember
Data typeA set of values and a set of operations on them
Two categoriesPrimitive and reference
Primitive coversNumbers and Boolean values
In this courseint, double, boolean
Reference coversObjects that are not primitive types
Primitive variableHolds the value itself
Reference variableHolds a reference to an object elsewhere
ReassigningPrimitive: the old value is gone. Reference: the old object survives
The habit

Given a specification, ask two questions in order. Is it a number or a true/false? — that gives you the category. Then what will I actually do with it? — that catches the phone number, where the values look numeric and the operations are not.