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
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.
| Type | Its set of values | Its set of operations |
|---|---|---|
int | Whole numbers in a fixed range | + - * / %, comparisons |
double | Real numbers | + - * /, comparisons |
boolean | Exactly true and false | && || ! |
String | Sequences of characters | length(), substring(), + to join |
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.
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
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.
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.
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
| Step | Category | What changed | What survived |
|---|---|---|---|
| 1 | Primitive | stock now holds 12 | — |
| 2 | Reference | model holds a reference; an object is created | — |
| 3 | Primitive | The 12 is replaced by 9 | Nothing — 12 is gone |
| 4 | Reference | The 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.
| Specification | Category | Because |
|---|---|---|
| How many frames are in stock at the Busan branch | Primitive | A whole-number count |
| The price of a service, to the cent | Primitive | A real number |
| Whether the branch is open on Sunday | Primitive | True or false |
| The model name printed on the frame | Reference | Text is an object, not a number |
| Every model the Daegu branch carries | Reference | A collection is an object |
| A customer, with a name and a phone number | Reference | A thing with parts — a class |
"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.
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.
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?
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?
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?
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
| Idea | What to remember |
|---|---|
| Data type | A set of values and a set of operations on them |
| Two categories | Primitive and reference |
| Primitive covers | Numbers and Boolean values |
| In this course | int, double, boolean |
| Reference covers | Objects that are not primitive types |
| Primitive variable | Holds the value itself |
| Reference variable | Holds a reference to an object elsewhere |
| Reassigning | Primitive: the old value is gone. Reference: the old object survives |
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.