Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


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

Difference Between 'float' and 'Float' Types

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

Answer:
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,
etc. 
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.

 

 

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