• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Very Basic Question

 
Peter Phung
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the difference between Float, int, Double, Long, Short?
I know its a dumb question, but i need to know the format that the number will be displayed.
I do know that an int is an integer i.e. 5;
and that Float has a decimal point i.e. 15.37;
but what about the other?
 
Jason Kretzer
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A basic way to put it is this:
long stands for "long integer" It is simply an integer that can have a higher max value.

double stands for "double precision"(if I am not mistaken) It is float that can have more digit after the decimal.
HTH,
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Peter Phung:
What is the difference between Float, int, Double, Long, Short?

Well, a quick answer is that, when you output a double, it will look a lot like a float (only with more decimal places) and a long and a short will look like an int.
However, the terminology you're using is somewhat incorrect. Remember, Java is case sensitive. Float is different from float. A float is a Java primitive and a Float is an object that encapsulaates a float primitive. This is one of the "wrapper" classes. There is a wrapper class available for every one of the 8 primitive types and void. For the most part, the wrapper classes have the same names as the primitives they wrap, except that they have a capital first letter. For example, the wrapper for a float primitive is a Float object. The exceptions to this rule are the wrapper for an int primitive, which is an Integer object, and the wrapper for a char primitive, which is a Character object.
Be sure to check out the API for all sorts of good information on these wrapper classes.
I hope that helps,
Corey
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Peter
On the off chance that you really meant:
float, int, double, long, short (notice - all lower case) then here are all fo the technical details from the JLS section 4.2.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And if you meant Short, Integer, Double, Long and Float, those are object-wrapped value classes for the intrinsic types.
hth,
bear
 
Mike Birken
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Numberical literals without a decimal point are assumed to be ints. Numberical literals with a decimal point are assumed to be doubles. To force a numerical literal to long, end it with an L (e.g. 100L). to force a numerical literal to a float, end it with an F (e.g. 100.0F).
- Mike
 
Peter Phung
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So is an Int an Object?
 
Matthew Haynes
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Int is invalid
Most of the wrapper classes follow the naming convention of "primitive name starting with a capital". Eg:
primitive/wrapper class
boolean/Boolean
byte/Byte
short/Short
long/Long
float/Float
double/Double
The two exceptions are integers and characters which are:
int/Integer
char/Character
Regards,
Matt
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic