> For the complete documentation index, see [llms.txt](https://www.pranaypourkar.co.in/the-programmers-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.pranaypourkar.co.in/the-programmers-guide/java/java-basics/java-data-types/default-values.md).

# Default Values

In Java, different types of variables have different default values when they are not explicitly initialized. Here are the default values for each type:

1. **Primitive Data Types**
   * `byte`, `short`, `int`, `long`: `0`
   * `float`, `double`: `0.0`
   * `char`: `'\u0000'` (null character)
   * `boolean`: `false`
2. **Reference Data Types**
   * For reference types (objects), the default value is `null`, meaning they do not refer to any object in memory.
3. **Local Variables**
   * Local variables must be explicitly initialized before they are used. They do not have default values. **Compilation** error will occur if not initialized and tried to use.

<figure><img src="https://3632859567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPd6ktrA5pPLsZJktj2fm%2Fuploads%2Fgit-blob-f863383c331ad1ed9bc2cfea5be82c7228733350%2Fimage.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

4. **Static and Instance Variables**

* If they are not explicitly initialized, they are automatically initialized with their default values. **Non-static - Non local variables will also be initialized.**

```java
public class Application {
    static int i1;
    static Integer i2;
    public static void main(String[] args) {
        System.out.println(i1); // 0
        System.out.println(i2); // null
    }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://www.pranaypourkar.co.in/the-programmers-guide/java/java-basics/java-data-types/default-values.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
