One returns Double; the other, double.

The differences between primitive Java types and their wrapper counterparts are discussed, for example, here.

Answer from NPE on Stack Overflow
🌐
Coderanch
coderanch.com › t › 409330 › java › Double-double-difference
Double and double - what's the difference? (Beginning Java forum at Coderanch)
It returns double, not Double. That should solve your problem. You should have got a compile time error because of this. However, if you are using JDK 1.5 or above then you would not get this problem. ... Originally posted by ankur rathi: You should have got a compile time error because of this.
🌐
Quora
quora.com › What-is-the-difference-between-double-d-new-Double-String-and-double-d-Double-parseDouble-String-in-Java
What is the difference between ' double d = new Double (String)' and ' double d = Double.parseDouble (String)' , in Java? - Quora
Both throws NumberFormatException if incorrect string value if given. Now the difference lies in what both of them return: new Double(String) is used when you want to create a Double instance . Since your first co...
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › Double.html
Double (Java Platform SE 8 )
October 20, 2025 - The argument is considered to be a representation of a floating-point value according to the IEEE 754 floating-point "double format" bit layout. If the argument is 0x7ff0000000000000L, the result is positive infinity. If the argument is 0xfff0000000000000L, the result is negative infinity. If the argument is any value in the range 0x7ff0000000000001L through 0x7fffffffffffffffL or in the range 0xfff0000000000001L through 0xffffffffffffffffL, the result is a NaN. No IEEE 754 floating-point operation provided by Java can distinguish between two NaN values of the same type with different bit patterns.
🌐
Coderanch
coderanch.com › t › 750518 › java › difference-double-Double-java
What is the difference between 'double' and 'Double' in java? (Beginning Java forum at Coderanch)
Junilu Lacar wrote:the compiler probably generates bytecode to invoke d2.doubleValue() to unbox it If you follow the link Campbell provided to the JLS section on unboxing conversions, you'll see my guess was right: The Java Language Specification 5.1.8 wrote:If r is a reference of type Double, then unboxing conversion converts r into r.doubleValue()
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-lang-double-class-java
Java.Lang.Double Class in Java - GeeksforGeeks
July 23, 2025 - Double class is a wrapper class for the primitive type double which contains several methods to effectively deal with a double value like converting it to a string representation, and vice-versa. An object of the Double class can hold a single double value. Double class is a wrapper class for the primitive type double which contains several methods to effectively deal with a double value like converting it to a string representation, and vice-versa.
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › Float-vs-Double-Whats-the-difference
Java double vs float: What's the difference?
–Dell Technologies & Intel® · Infrastructure for Machine Learning, AI Requirements, Examples –TechTarget · The key difference between a float and double in Java is that a double can represent much larger numbers than a float.
Find elsewhere
🌐
Reddit
reddit.com › r/learnjava › "double[] mylist = new double[10]" -- super easy noob question. why is double necessary to be stated twice?
r/learnjava on Reddit: "double[] myList = new double[10]" -- super easy noob question. why is double necessary to be stated twice?
April 14, 2015 -

As in, the way Java works, why was it designed this way.. I understand double[] myList but why is it necessary to state double... same thing with like... Scanner input = new Scanner(System.in)

it just feels... redundant.. but im at such a low level, my curiosity got to me. whats the utility of this?

can you show me a short line of code that shows the deeper complexity of declaring a new instance.

id imagine its just a syntax thing built into java/previous languages.. but i guess from my experience with higher level languages seem to have really simplified the type of statement above

Top answer
1 of 5
8
I'm going to use a List example to explain this, because it's pretty easy to see. An object in Java (and many other languages) has two parts. One is the actual object itself that lives on the heap. It contains information about the object, like member variables. The other part of the object is a reference which controls the object. The references know generally what kinds of actions you can take with the object. Think of the reference like a remote control and an object like a TV. When you declare an object, you have a two-part declaration. Let's say I want to create a dynamic list of integers. My declaration is going to look like this: ArrayList intList = new ArrayList(); The left side of the declaration tells the compiler what type the reference (remote control) is. Here I've been pretty specific and declared my intList reference as an ArrayList. However, I didn't need to. I could have also said: List intList = new ArrayList(); My remote control has become more general. It's kind of like using a universal remote, instead of the one that's designed specifically for your television. The right side of the = in the object declaration is telling Java what type of object it's allocating space for on the heap. This needs to be specific. I can't say intList is a List on the right side. The compiler won't let you do that, since List is an interface and not able to be instantiated. Now, why do we do this? A couple reasons, which all fall under the general heading of "Polymorphism". If I have my intList declared as a List instead of an ArrayList, I can pass it to any method that takes a List in its method signature. The same method would also be able to take anything else that implements the List interface, such as LinkedList. This becomes even more powerful when you build your own objects. Let's say you're writing some sort of program to run a farm. You'll probably have an Animal class, as well as a bunch of different things that inherit from Animal, such as Cow, Horse, and Pig. Let's also say you have a barn that you house the animals in. Instead of having three different ArrayLists for the animals in your barn, you can have a single ArrayList to hold them all. When you create it, you just say: List barnAnimals = new ArrayList(); And you'll be able to add any type of animal to it, instead of just horses or pigs. You can also declare any of the animals like so: Animal bessie = new Cow(); A final word of warning. If you do this, the only methods you'll be able to access from the reference (remote control) are the methods of the parent class you're declaring it as, in this case Animal. So you'd probably have eat() or sleep(), since those are common for all the animals on a farm, but you wouldn't be able to say bessie.milk(); with the way we've declared it. You'd have to first cast Bessie as a cow before you'd be able to do any cow-specific actions with her.
2 of 5
1
It has to do with classes and inheritance from what I understand. If the FantasyNovel class inherits the Book class, then you could declare a fantasy novel as a book. Someone who has done this in practice would be a better source and you should double check me.
🌐
Software Testing Help
softwaretestinghelp.com › home › java › java double – tutorial with programming examples
Java Double - Tutorial With Programming Examples
April 1, 2025 - Every time when we do a certain ... return a new object instead of modifying the already created objects. Q #4) What is the difference between float and double? Answer: Enlisted below are the differences between float and double. ... Answer: A Math class is a class in Java that contains ...
🌐
Tutorialspoint
tutorialspoint.com › home › java/lang › java double class overview
Java Double Class Overview
September 1, 2008 - Explore the Java Double class, its methods, and functionalities. Learn how to use Double for floating-point arithmetic in Java.
Top answer
1 of 2
21

Explanation

You should replace it with:

d[i] = Double.valueOf(d.length - i);

From its Javadoc:

Deprecated.

It is rarely appropriate to use this constructor. The static factory valueOf(double) is generally a better choice, as it is likely to yield significantly better space and time performance.

In general, valueOf is not forced to always return a new instance. It can utilize an internal cache and re-use values created before already, which makes it faster. For example if you create hundreds of 1.0.


Note

Is there a specific reason you are using a Double[] in the first place? If not, go for double[] instead. The primitives are much faster and have less memory overhead, compared to their object wrapper.

Then your code is just:

double[] d = new double[10];
for (int i = 0; i < d.length; i++)
    d[i] = d.length - i;

By the way, you should prefer to never omitt the curly braces. Even if your loop is just one line. This is a very common source for bugs that are hard to find.

Also, your variable naming is not very good. What is d? Try to give it a name that reflects what it actually means. Like ages if it stores person ages, for example. If you do not have something specific, maybe use values. That is already better than just d. Especially since it is plural, so it is clear that it is an array of multiple values.

double[] values = new double[10];
for (int i = 0; i < values.length; i++) {
    values[i] = values.length - i;
}
2 of 2
1

From Java 9 constructor(s) method(s) was Deprecated

Deprecated. It is rarely appropriate to use this constructor. The static factory valueOf(double) is generally a better choice, as it is likely to yield significantly better space and time performance. Constructs a newly allocated Double object that represents the primitive double argument.

So replace with:

Double.valueOf(d.length - i)
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › docs › api › java.base › java › lang › Double.html
Double (Java SE 17 & JDK 17)
January 20, 2026 - P where Sign, FloatingPointLiteral, HexNumeral, HexDigits, SignedInteger and FloatTypeSuffix are as defined in the lexical structure sections of The Java Language Specification, except that underscores are not accepted between digits. If s does not have the form of a FloatValue, then a NumberFormatException is thrown. Otherwise, s is regarded as representing an exact decimal value in the usual "computerized scientific notation" or as an exact hexadecimal value; this exact numerical value is then conceptually converted to an "infinitely precise" binary value that is then rounded to type double by the usual round-to-nearest rule of IEEE 754 floating-point arithmetic, which includes preserving the sign of a zero value.
🌐
Java
download.java.net › java › early_access › valhalla › docs › api › java.base › java › lang › Double.html
Double (Java SE 23 & JDK 23 [build 1])
Returns a Double instance representing the specified double value. If a new Double instance is not required, this method should generally be used in preference to the constructor Double(double), as this method is likely to yield significantly better space and time performance by caching frequently ...
🌐
University of Washington
courses.cs.washington.edu › courses › cse341 › 98au › java › jdk1.2beta4 › docs › api › java › lang › Double.html
Class java.lang.Double
There is always a minimum of one digit after the decimal point. The number of digits is the minimum needed to uniquely distinguish the argument value from adjacent values of type double. ... Returns a new Double value initialized to the value represented by the specified String.
🌐
DataCamp
datacamp.com › doc › java › double
double Keyword in Java: Usage & Examples
Java keywordsIntroduction To JavaJava File HandlingJava Language BasicsJava ArraysJava Object-Oriented Programming ... The double keyword in Java is a primitive data type that represents a double-precision 64-bit IEEE 754 floating point.