---
title: "What is the difference between \"Double\" and \"double\" in Java?"  
description: "What is the difference between \"Double\" and \"double\" in Java?"  
author: "Steilla Mitchel"  
published: 2023-08-18  
updated: 2023-08-19  
canonical: https://www.mindstick.com/forum/159583/what-is-the-difference-between-double-and-double-in-java  
category: "java"  
tags: ["java", "Data Types"]  
reading_time: 2 minutes  

---

# What is the difference between "Double" and "double" in Java?

What is the [difference](https://www.mindstick.com/articles/157114/good-news-or-bad-news-and-the-difference-is) between "Double" and "double" in [Java](https://www.mindstick.com/articles/12214/web-development-company-in-india-laid-on-the-foundation-of-concrete-java-programming)?

## Replies

### Reply by Aryan Kumar

In Java, `double` and `Double` are two different things.

- `double` is a primitive data type, while `Double` is a class.
- A primitive data type is a basic data type that is built into the language. A class is a user-defined data type that can be created by the programmer.
- A `double` variable stores a floating-point number. A `Double` object stores a reference to a floating-point number.

Here is an example:

Java

```plaintext
double d = 1.23;
Double obj = new Double(1.23);
```

In this example, `d` is a `double` variable that stores the floating-point number 1.23. `obj` is a `Double` object that stores a reference to the same floating-point number.

The main difference between `double` and `Double` is that `double` is a value type, while `Double` is a reference type. This means that `double` variables are stored directly on the stack, while `Double` objects are stored on the heap.

Reference types are more complex than value types and require more memory. However, they also offer more flexibility, as they can be used to store null values and they can be used in generics.

In general, you should use `double` when you need to store a floating-point number and you do not need the flexibility of a reference type. You should use `Double` when you need to store a floating-point number and you need the flexibility of a reference type.


---

Original Source: https://www.mindstick.com/forum/159583/what-is-the-difference-between-double-and-double-in-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
