Data Type

In AP Computer Science A, a data type is the classification Java gives a value, like int, double, boolean, or String, that determines how much memory it uses, what operations are legal on it, and whether it's stored as a primitive value or a reference to an object.

Verified for the 2027 AP Computer Science A examLast updated June 2026

What is Data Type?

A data type is Java's label for what kind of value something is. Every variable, parameter, and return value in Java must declare a type, and that type controls everything that happens next. It decides what values you can store (you can't put 3.7 in an int), what operations make sense (you can divide two doubles, but you can't divide two booleans), and how the value behaves when you pass it around your program.

For AP CSA, data types split into two big families. Primitive types hold the value directly. The exam's Java subset focuses on int, double, and boolean. Reference types hold a memory address that points to an object, like String, Scanner, or any class you write yourself. That one distinction (value vs address) explains a huge amount of weird-looking Java behavior, from why == doesn't compare String contents to why a method can change an object's state but can't change a primitive you pass in.

Why Data Type matters in AP Computer Science A

Data types are the foundation of Unit 1 (Primitive Types) and Unit 2 (Using Objects), and they never go away. Every method header you write on an FRQ declares a return type and parameter types. Every variable declaration starts with a type. The compiler enforces types strictly, so understanding them is how you avoid compile-time errors on multiple-choice questions and how you write headers that actually earn points on free-response questions. The primitive vs reference distinction also drives later units, since arrays, ArrayLists, and your own classes are all reference types whose variables store addresses, not the data itself.

How Data Type connects across the course

Primitive Data (Unit 1)

Primitives like int, double, and boolean store their value directly in the variable. Copy a primitive and you get a completely independent copy, which is why a method can't change the original int you passed it.

Reference Data (Unit 2)

Reference types store an address, not the object itself. Two variables can point to the same object, so changing the object through one variable changes what the other one sees. This is the single biggest 'aha' about data types in CSA.

Return Type (Unit 2)

Every method header declares a data type for what it gives back, or void if it returns nothing. On FRQs, a wrong return type in your method header can cost you, so match the type the prompt asks for exactly.

Default Values (Unit 5)

When instance variables aren't initialized, their data type decides the default. Numeric primitives become 0, booleans become false, and reference types become null. That null is where NullPointerExceptions are born.

Is Data Type on the AP Computer Science A exam?

Data types show up constantly in multiple choice, usually disguised as questions about something else. You'll see stems like 'which primitive type is most appropriate' for a given situation (a boolean for tracking complete/incomplete assignments, for example), questions asking which operation causes a compile-time error when types don't match, and questions testing whether you know that primitives and references behave differently when passed to methods. Watch for the classics, like int division truncating (7 / 2 is 3, not 3.5) and mixing types in an expression. On FRQs, types are graded silently. Your method signatures, variable declarations, and return statements all have to use the right types, or the code doesn't compile in the grader's eyes.

Data Type vs Variable

A variable is the named container; a data type is the rule for what fits inside it. In int count = 5;, the variable is count and the data type is int. The type is set once at declaration and never changes, while the variable's value can change as the program runs (as long as new values match the type).

Key things to remember about Data Type

  • A data type tells Java what kind of value a variable holds and which operations are legal on it.

  • The AP CSA Java subset centers on three primitive types (int, double, boolean), and everything else, including String, is a reference type.

  • Primitive variables store the value itself, while reference variables store the address of an object, which is why methods can modify objects but not the primitives passed to them.

  • Type mismatches cause compile-time errors, so operations like assigning a double to an int without casting will not compile.

  • Integer division truncates the decimal, so 7 / 2 evaluates to 3, and you need a double in the expression to get 3.5.

  • Uninitialized instance variables get defaults based on their type: 0 for numbers, false for boolean, and null for reference types.

Frequently asked questions about Data Type

What is a data type in AP Computer Science A?

A data type is the classification Java assigns to a value, like int, double, boolean, or String, that determines what the value can be and what operations you can perform on it. Every variable, parameter, and method return in Java must declare one.

Is String a primitive data type in Java?

No. String is a reference type, meaning a String variable stores the address of a String object, not the text itself. That's why you compare String contents with .equals() instead of ==, which only checks if two references point to the same object.

What's the difference between a data type and a variable?

The variable is the named storage location and the data type is the rule for what can go in it. In double price = 4.99;, price is the variable and double is its type. The value can change later, but the type can't.

What primitive data types do I need to know for the AP CSA exam?

The exam's Java subset focuses on int, double, and boolean. You should also know that mixing them has rules, like int division truncating to an int and an int automatically widening to a double in mixed expressions.

Why does it matter whether a data type is primitive or reference?

Because they're passed to methods differently. A method gets a copy of a primitive's value, so the original can't be changed, but it gets a copy of a reference, so the method can still modify the object that reference points to. The exam tests this distinction directly.