Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Java Language
Expertise: Beginner
Mar 20, 1997



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Difference Between 'float' and 'Float' Types

What is the difference between the types 'float' and 'Float' in Java?

A variable of type float contains an IEEE single precision number, while a variable of type Float contains a pointer to an object encapsulating an IEEE single precision number.

The class Float is called an object wrapper of the type float. The designers of Java found it convenient to introduce object wrappers for all the primitive types: int:Integer, boolean:Boolean, etc.

This is convenient for representing heterogeneous collections of primitive values. For example, it's easy to create an array containing an odd assortment of objects since all objects can be implicitly cast to the class Object.

Object[] things; // holds instances of Bike, Shoe, Gum,
On the other hand, there is no "most general type" to which all primitive values can be promoted. (Every primitive value can be promoted to a double except booleans.)
double[] items; //
holds numbers, chars, but not booleans
However, things can hold instances of Boolean, Char, and Number.
DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date