Default Values

In AP Computer Science A, default values are the values Java automatically assigns when you don't initialize something yourself: 0 for int, 0.0 for double, false for boolean, and null for object references. Instance variables and array elements get defaults; local variables do not.

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

What are Default Values?

When you declare an instance variable or create an array without giving it a value, Java doesn't leave it as garbage. It fills in a default. The defaults follow a simple pattern by type: int becomes 0, double becomes 0.0, boolean becomes false, and any reference type (like String or your own class) becomes null. So if you write new int[10], you instantly have ten zeros, and if a class has an instance variable private String name; that no constructor touches, name starts as null.

Here's the catch that trips people up. This automatic filling only happens for instance variables and array elements. Local variables declared inside a method get nothing. If you declare int x; inside a method and try to use x before assigning it, your code won't even compile. So "Java gives everything a default value" is only half true, and the exam loves living in that half-truth.

Why Default Values matter in AP Computer Science A

Default values show up everywhere in AP CSA even though they're not a headline topic. In Unit 1 you learn that primitive types each have a zero-like default. In Unit 2 you see that uninitialized object references are null, which is exactly where NullPointerException comes from. In Unit 5, defaults explain what your objects actually look like when a constructor doesn't set every instance variable, and they connect to the default (no-argument) constructor Java provides when you write no constructor at all. In Unit 6, defaults explain why a freshly created int array is all zeros and a freshly created object array is all null. Tracing code on the exam often means knowing what a value is before anyone explicitly sets it, and default values are the answer.

How Default Values connect across the course

Initialization (Units 1 & 5)

Initialization is you choosing a starting value; default values are what Java picks when you don't. A constructor's whole job is to override defaults with meaningful starting values for an object's state.

Primitive Data Types (Unit 1)

Each primitive has a predictable default that's basically 'zero in that type's language': 0 for int, 0.0 for double, false for boolean. Reference types break the pattern by defaulting to null instead.

Object's State (Units 2 & 5)

An object's state is the current values of its instance variables. If a constructor forgets one, that piece of state silently starts at its default, which is a classic source of wrong-output bugs in code-tracing questions.

ArrayIndexOutOfBoundsException (Unit 6)

Both come up when you reason about arrays. Accessing a valid index of a new int array gives you 0 (a default value); accessing an invalid index gives you an exception. Knowing which happens when is pure exam fuel.

Are Default Values on the AP Computer Science A exam?

Default values are tested indirectly but constantly. Multiple-choice questions ask things like "What happens if no constructor is defined in a class?" (Java supplies a no-argument constructor, and instance variables get their default values) or have you trace code where an instance variable was never explicitly set. On FRQs, defaults matter when you write class designs. The 2019 StepTracker FRQ required initializing counters like total steps and active days, and the safest habit is to explicitly set every instance variable in your constructor rather than relying on Java's defaults. Graders reward code that clearly initializes state. Also know the array case cold. After int[] arr = new int[5];, every element is 0, no loop required.

Default Values vs Default constructor

A default value is what Java assigns to an uninitialized instance variable or array element (0, 0.0, false, null). A default constructor is the no-argument constructor Java automatically provides only when you write no constructors at all. They're related, because an object built by the default constructor ends up with all instance variables at their default values, but one is a value and the other is a method.

Key things to remember about Default Values

  • Java assigns default values to instance variables and array elements: 0 for int, 0.0 for double, false for boolean, and null for any object reference.

  • Local variables inside methods do NOT get default values, and using one before assigning it causes a compile-time error.

  • A new array is automatically filled with defaults, so new int[10] is ten zeros and a new String array is all null.

  • If a class has no constructor, Java provides a default no-argument constructor, and every instance variable starts at its default value.

  • An instance variable left at null and then used (like calling a method on it) is the root cause of NullPointerException.

  • On FRQs, explicitly initialize every instance variable in your constructor instead of relying on defaults; it's clearer and safer for points.

Frequently asked questions about Default Values

What are the default values in Java for AP CSA?

Instance variables and array elements default to 0 for int, 0.0 for double, false for boolean, and null for reference types like String or any class you write. These are the only defaults you need for the AP exam.

Do local variables get default values in Java?

No. Only instance variables and array elements get defaults. A local variable declared inside a method must be assigned before use, or the code won't compile, which is a favorite multiple-choice trap.

What is the difference between a default value and a default constructor?

A default value is the automatic value of an uninitialized instance variable (like 0 or null). A default constructor is the no-argument constructor Java creates for you only when a class defines no constructors at all. The default constructor leaves instance variables at their default values.

What is the default value of a String in Java?

null, not an empty string. String is a reference type, so an uninitialized String instance variable is null, and calling any method on it throws a NullPointerException.

Are the elements of a new array initialized in Java?

Yes. Creating an array with new automatically fills every element with the type's default value, so new double[3] holds three 0.0 values and a new array of objects holds all null references.