---
title: "Null — AP Computer Science A Definition & Exam Guide"
description: "Null is Java's special value meaning a reference variable points to no object. Learn how null causes NullPointerExceptions and shows up on AP CSA MCQs and FRQs."
canonical: "https://fiveable.me/ap-comp-sci-a/key-terms/null"
type: "key-term"
subject: "AP Computer Science A"
unit: "Unit 4"
---

# Null — AP Computer Science A Definition & Exam Guide

## Definition

In AP Computer Science A, null is the special Java value that means a reference variable does not refer to any object. Calling a method or accessing data through a null reference throws a NullPointerException, one of the most commonly tested runtime errors on the exam.

## What It Is

Null is Java's way of saying "this [variable](/ap-comp-sci-a/unit-1/expressions-and-assignment-statements/study-guide/01dr6uUPDAn3SjtK2Psr "fv-autolink") exists, but it isn't pointing at anything yet." [Reference](/ap-comp-sci-a/key-terms/reference "fv-autolink") variables (like `String`, `Rectangle`, or `ArrayList` variables) don't hold objects directly. They hold a reference, basically an arrow pointing to an object in memory. When that arrow points at nothing, the variable's value is `null`.

You'll meet null in a few predictable places. Instance variables of a reference type (like a `String` field in a [class](/ap-comp-sci-a/unit-3/abstraction-and-program-design/study-guide/o9VgVeIpKRYZ7N7rXfUz "fv-autolink")) automatically default to `null` if a constructor never assigns them. A variable you declare without using the `new` keyword starts as null too. The danger comes when you try to use a null reference, like calling `playerName.length()` when `playerName` was never assigned. Java can't call a method on nothing, so it throws a `NullPointerException` and your program crashes. A huge chunk of debugging in AP CSA comes down to tracking which references are null and when.

## Why It Matters

Null sits at the heart of how Java handles [objects](/ap-comp-sci-a/key-terms/object "fv-autolink"), which is the backbone of Units 2 and 5 (Using Objects and Writing Classes). The CED expects you to know [default values](/ap-comp-sci-a/key-terms/default-values "fv-autolink"), and they split by type. Primitive instance variables like `int` default to 0 and `double` to 0.0, but reference-type instance variables default to `null`. That distinction shows up constantly in MCQs that ask about an object's state right after construction. Null also matters for safe code. Before calling a method on an object that might not exist, you check `if (obj != null)` first. Skipping that check is exactly how a `NullPointerException` happens, and recognizing when code will throw one is a classic exam skill.

## Connections

### Default Value (Unit 5)

Null IS the default value for reference-type [instance variables](/ap-comp-sci-a/key-terms/instance-variables "fv-autolink"). If a constructor sets `length` and `width` but never touches a `String name` field, that field is null automatically. Exam questions love asking what an object's state is right after a constructor runs, and the answer often includes a null somewhere.

### [New Keyword (Unit 2)](/ap-comp-sci-a/key-terms/new-keyword)

The `new` keyword is the opposite of null. Writing `Rectangle r;` gives you a [null reference](/ap-comp-sci-a/key-terms/null-reference "fv-autolink"), while `Rectangle r = new Rectangle(3, 4);` actually creates an object for `r` to point to. If you forget `new`, every method call on that variable throws a NullPointerException.

### Empty String (Unit 2)

A null String and an empty String (`""`) are completely different. An empty String is a real object with length 0, so you can call methods on it safely. A null String is no object at all, so `s.length()` crashes. This is one of the most commonly tested distinctions in early CSA units.

### [ArrayIndexOutOfBoundsException (Unit 6)](/ap-comp-sci-a/key-terms/arrayindexoutofboundsexception)

NullPointerException and [ArrayIndexOutOfBoundsException](/ap-comp-sci-a/key-terms/arrayindexoutofboundsexception "fv-autolink") are the two runtime errors you're most likely to see in MCQ answer choices. One means the reference points at nothing, the other means the array exists but you reached past its edge. Knowing which error a code segment produces is a frequent exam ask.

## On the AP Exam

Null is tested in two main ways. On the multiple-choice section, expect code segments where you have to predict whether a `NullPointerException` occurs, like a constructor that never initializes a reference field, or a method called on a variable that was declared but never assigned with `new`. Questions about an object's state right after construction also hinge on knowing that reference fields default to null while primitives default to 0 or 0.0. On the FRQs, null shows up as a defensive-coding habit. Class design and ArrayList questions (like the 2017 free-response set built around classes such as Digits and Phrase) reward you for initializing instance variables in constructors so your references are never accidentally null, and for checking `!= null` before using objects that might not exist. You won't write an essay about null, but you will lose points if your code calls methods on references you never initialized.

## null vs Empty String

An empty String (`""`) is a real String object that happens to contain zero characters, so `s.length()` returns 0 and `s.equals("")` returns true. Null means there is no String object at all, so calling any method on it throws a NullPointerException. Think of it like a mailbox. An empty String is an empty mailbox, while null means the mailbox was never installed.

## Key Takeaways

- Null means a reference variable points to no object at all, not that it holds zero or an empty value.
- Calling any method or accessing any field through a null reference throws a NullPointerException at runtime.
- Reference-type instance variables default to null if a constructor never assigns them, while primitive instance variables default to 0, 0.0, or false.
- A null String and an empty String are different. The empty String is a real object with length 0, so methods work on it safely.
- Using the `new` keyword is what replaces null with an actual object, so a declared-but-never-constructed variable stays null.
- Checking `if (obj != null)` before using an object is the standard way to avoid NullPointerExceptions in FRQ code.

## FAQs

### What is null in AP Computer Science A?

Null is the special Java value meaning a reference variable doesn't point to any object. It's the automatic starting value for reference-type instance variables like String or Rectangle fields that a constructor never initializes.

### Is null the same as 0 or an empty string in Java?

No. Zero is a primitive int value and "" is a real String object with zero characters, but null means there's no object at all. You can call methods on an empty String safely, while calling any method on null crashes with a NullPointerException.

### What causes a NullPointerException on the AP CSA exam?

It happens when code calls a method or accesses a field through a reference that is null, like calling `name.length()` when `name` was declared but never assigned with `new` or in a constructor. Spotting this in code segments is a classic multiple-choice question.

### Do int and double variables ever equal null?

No. Primitives like int, double, and boolean can never be null because they hold actual values, not references. Only reference types (String, arrays, ArrayList, and any class you write) can be null. As instance variables, primitives default to 0, 0.0, or false instead.

### How do I avoid NullPointerExceptions in my FRQ code?

Initialize every reference-type instance variable in your constructors, always use `new` before calling methods on an object, and check `if (obj != null)` when an object might not exist. These habits keep your FRQ solutions from losing points to runtime errors.

## Related Study Guides

- [4.11 2D Arrays](/ap-comp-sci-a/unit-4/2d-arrays/study-guide/5WDx6ZFeWhx2aVuiZI6R)

## Structured Data

```json
{"@context":"https://schema.org","@graph":[{"@type":"LearningResource","@id":"https://fiveable.me/ap-comp-sci-a/key-terms/null#resource","name":"Null — AP Computer Science A Definition & Exam Guide","url":"https://fiveable.me/ap-comp-sci-a/key-terms/null","learningResourceType":"Concept explainer","educationalLevel":"AP® / High School","about":{"@id":"https://fiveable.me/ap-comp-sci-a/key-terms/null#term"},"audience":{"@type":"EducationalAudience","educationalRole":"student"},"dateModified":"2026-06-11T00:50:33.088Z","isPartOf":{"@type":"Collection","name":"AP Computer Science A Key Terms","url":"https://fiveable.me/ap-comp-sci-a/key-terms"},"publisher":{"@type":"Organization","name":"Fiveable","url":"https://fiveable.me"}},{"@type":"DefinedTerm","@id":"https://fiveable.me/ap-comp-sci-a/key-terms/null#term","name":"null","description":"In AP Computer Science A, null is the special Java value that means a reference variable does not refer to any object. Calling a method or accessing data through a null reference throws a NullPointerException, one of the most commonly tested runtime errors on the exam.","url":"https://fiveable.me/ap-comp-sci-a/key-terms/null","inDefinedTermSet":{"@type":"DefinedTermSet","name":"AP Computer Science A Key Terms","url":"https://fiveable.me/ap-comp-sci-a/key-terms"}},{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"What is null in AP Computer Science A?","acceptedAnswer":{"@type":"Answer","text":"Null is the special Java value meaning a reference variable doesn't point to any object. It's the automatic starting value for reference-type instance variables like String or Rectangle fields that a constructor never initializes."}},{"@type":"Question","name":"Is null the same as 0 or an empty string in Java?","acceptedAnswer":{"@type":"Answer","text":"No. Zero is a primitive int value and \"\" is a real String object with zero characters, but null means there's no object at all. You can call methods on an empty String safely, while calling any method on null crashes with a NullPointerException."}},{"@type":"Question","name":"What causes a NullPointerException on the AP CSA exam?","acceptedAnswer":{"@type":"Answer","text":"It happens when code calls a method or accesses a field through a reference that is null, like calling `name.length()` when `name` was declared but never assigned with `new` or in a constructor. Spotting this in code segments is a classic multiple-choice question."}},{"@type":"Question","name":"Do int and double variables ever equal null?","acceptedAnswer":{"@type":"Answer","text":"No. Primitives like int, double, and boolean can never be null because they hold actual values, not references. Only reference types (String, arrays, ArrayList, and any class you write) can be null. As instance variables, primitives default to 0, 0.0, or false instead."}},{"@type":"Question","name":"How do I avoid NullPointerExceptions in my FRQ code?","acceptedAnswer":{"@type":"Answer","text":"Initialize every reference-type instance variable in your constructors, always use `new` before calling methods on an object, and check `if (obj != null)` when an object might not exist. These habits keep your FRQ solutions from losing points to runtime errors."}}]},{"@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"AP Computer Science A","item":"https://fiveable.me/ap-comp-sci-a"},{"@type":"ListItem","position":2,"name":"Key Terms","item":"https://fiveable.me/ap-comp-sci-a/key-terms"},{"@type":"ListItem","position":3,"name":"Unit 4","item":"https://fiveable.me/ap-comp-sci-a/unit-4"},{"@type":"ListItem","position":4,"name":"null"}]}]}
```
