Question:

What is the difference between Double and double in Java?

by  |  earlier

0 LIKES UnLike

What is the difference between Double and double in Java? Like when declaring a double...

double decimalNumber=0.0;

OR

Double decimalNumber=0.0;

Both work, but when I tried to change a variable I declared as a "Double" to "double" it got teh pissed.

 Tags:

   Report

2 ANSWERS


  1. Double is a class while double is a primitive. In other words, Double has a bunch of methods while all you can do with double is use it in arithmetical expressions.

    There are similar constructs for all the other primitive types too.


  2. As fishywiki said, double is a primitive and Double is a class.

    I see that in fact you are using at least Java 5. In the code:

    Double decimalNumber=0.0;

    you are creating (with "autoboxing") an object. If you were using Java 1.4, you had to write:

    Double decimalNumber=new Double(0.0);

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.