What is the difference between double and double in java




















Java Training Java Tutorial. Abstract class Interface Abstract vs Interface. Package Access Modifiers Encapsulation. Next Topic Java Keywords. Reinforcement Learning. R Programming. React Native. Python Design Patterns. Python Pillow. Python Turtle. Verbal Ability. Interview Questions. Find centralized, trusted content and collaborate around the technologies you use most. Connect and share knowledge within a single location that is structured and easy to search.

Double is an object and double is a primitive data type. See this answer for more details. The Double class wraps a value of the primitive type double in an object. An object of type Double contains a single field whose type is double. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. What is the difference between "Double" and "double" in Java?

On the other hand, double stores values from 1. Moreover, one other difference between long and double in Java is that long is an integral type while double is a floating point type. In conclusion, long and double are two primitive data types available in Java programming language. Programmer can use a data type according to the storing data. In brief, long is an integral type whereas double is a floating point type.

Java Data Types, Available here. She is passionate about sharing her knowldge in the areas of programming, data science, and computer systems. View all posts. What should I do to make this work. Reddy Prasad Kurapati Venkata. Double is a class.

That should solve your problem. You should have got a compile time error because of this. However, if you are using JDK 1. Joanne Neal. Double expected or required: double The compiler parsed the left hand side of the statement first and found a Double, therefore it expects the right hand side of the statement to also be a Double, but it's not - it's a double. Thanks Joanne. Andre Brito. But when I'm expecting Double, I can get an double, right?

Here it worked just fine. I'm using Java 6. Raghavan Muthu. It is wrong! In that case, the compiler expects the "double" primitive variable on the left hand side as the static method "parseDouble String " of class Double returns the primitive double.

As such, as ankur pointed out, had the code been compiled into JDK 1. I believe the code was compiled by using 1. That's when the compiler should have given an error saying that "required is double; but found is Double" as the variable "x" is of type Wrapper class Double. The assignment always happens from Right to Left That's right, but I never mentioned assignment.

Though you have not mentioned, but it is the fact! The compiler and the runtime environment works in the same order Right-to-Left for the assignment operator since the expression here deals with one.

And as such, the assignment works in the same way no matter what and since it gives an error because of checking at the RHS first and it finds out that the return value from the Double. But since the actual variable "x" available is of type wrapper Double, it complains.

Guys slow down a little. I've never had so many relies before. Ok so I understand the difference between a double and a Double but say I just want to input a number with decimal points gods knows whether that's a double or a Double using a BufferedReader, how do I do that?

I've tried doing this but I get a data type error: import java. Oh sorry, wrong code.



0コメント

  • 1000 / 1000