In AP Computer Science A, a variable declaration creates a variable by stating its data type and name (like int score;), telling Java what kind of value the variable can hold and reserving memory for it before the variable is used anywhere in the program.
A variable declaration is how you bring a variable into existence in Java. You write the data type first, then the name: int score; or double gpa; or String name;. Java is a statically typed language, which means every variable's type is locked in at declaration. Once score is declared as an int, it can only ever hold int values. Try to stuff a String in there and the compiler refuses to run your code.
Declaration is just the birth certificate. It does not give the variable a value. That second step is initialization, and you can do both in one line (int score = 0;) or separately. In AP CSA you'll declare local variables inside methods, parameters in method headers, and instance variables (usually marked private) inside classes. Same syntax everywhere, just different locations and lifetimes.
Variable declaration lives in Unit 1 (Primitive Types), where the CED expects you to declare variables of the correct type to represent primitive data like int, double, and boolean. It's arguably the first real Java skill the course builds, and everything else stacks on it. Reference variables for objects in Unit 2, parameter declarations in method signatures, and private instance variable declarations in Unit 5 all use the exact same type-then-name pattern. On the exam, sloppy declarations cost real points. An FRQ response that uses a variable without declaring it, or declares it with the wrong type, loses credit even if the logic is right. Choosing int when a calculation needs double is one of the most common self-inflicted wounds in AP CSA.
Variable Initialization (Unit 1)
Declaration creates the variable; initialization gives it its first value. Java lets you do both at once (int x = 5;), which is why so many people blur the two. On FRQs, the safest habit is to declare and initialize on the same line so you never use a variable that doesn't have a value yet.
Data Types (Unit 1)
Every declaration starts with a type, so you literally cannot declare a variable without making a data-type decision. Picking int vs. double matters because integer division truncates. Declare a variable as int when you need decimal precision and your average calculation silently drops everything after the decimal point.
Scope (Unit 5)
Where you declare a variable decides where it exists. Declare it inside a for loop and it dies when the loop ends; declare it as a private instance variable and it lives as long as the object does. Scope questions are really just questions about declaration location.
Scanner class (Unit 1)
Many intro classes use Scanner to read user input into declared variables, like int age = input.nextInt();. It's a nice way to practice matching declared types to incoming data, but heads up, Scanner itself isn't part of the AP Java subset, so the exam won't test you on it.
You won't get an MCQ that asks "what is a variable declaration?" Instead, the exam tests whether you can read and write declarations correctly. Multiple-choice questions hand you code with declarations baked in and expect you to track each variable's type, especially when int vs. double changes the result of division. On the free-response section, declaring your variables is non-negotiable. Every FRQ where you write a method body or a class requires you to declare local variables with correct types and declare instance variables as private in class-design questions. Using an undeclared variable, redeclaring a parameter, or mismatching types are all errors the scoring guidelines penalize. The skill being graded is precise, compilable Java, and declarations are where that precision starts.
Declaration tells Java a variable exists and what type it is (int count;). Initialization assigns it its first value (count = 0;). The line int count = 0; does both at once, which is why the terms get tangled. The distinction matters because Java won't let you use a local variable that's been declared but never initialized; the compiler flags it as an error.
A variable declaration in Java states the data type followed by the variable name, like int score; and this must happen before the variable is used.
Java is statically typed, so the type you declare is permanent; an int variable can never hold a String or a double.
Declaration and initialization are different steps. Declaring creates the variable, initializing gives it a value, and int x = 5; does both in one line.
Where you declare a variable controls its scope, so a variable declared inside a loop or method only exists there.
On FRQs, you lose points for using variables you never declared or for declaring them with a type that breaks the math, like using int where decimal division is needed.
In Unit 5 class-design questions, instance variables must be declared private to earn full credit.
It's the statement that creates a variable by giving it a data type and a name, like int count; or double price;. It tells Java what kind of value the variable holds and makes the name usable in your code.
Declaration creates the variable and fixes its type (int count;), while initialization assigns its first value (count = 0;). You can combine them as int count = 0;, which is the cleanest habit for FRQ code.
Yes. Java is statically typed, so every variable must be declared with a type before it's used, and the code won't compile otherwise. This is different from languages like Python, where you just assign a value and go.
No. Once you declare a variable as an int, it stays an int for its entire scope. You can change its value as many times as you want, but assigning a value of the wrong type causes a compiler error.
Yes, using an undeclared variable counts as an error under the scoring guidelines. Always declare local variables with the right type, and in class-design FRQs, declare instance variables as private.