It's not a secret anymore!
The moose likes Beginning Java and the fly likes Very Basic Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Very Basic Question" Watch "Very Basic Question" New topic

Very Basic Question

Peter Phung
Ranch Hand

Joined: Dec 06, 2001
Posts: 138
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?

Pete<br />"Reality is an illusion <br />brought on by a lack of <br />drink, drugs and smut"
Jason Kretzer
Ranch Hand

Joined: May 31, 2001
Posts: 280
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.

Jason R. Kretzer<br />Software Engineer<br />System Administrator<br /><a href="" target="_blank" rel="nofollow"></a>
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
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,

SCJP Tipline, etc.
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
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

Joined: Jan 10, 2002
Posts: 63343

And if you meant Short, Integer, Double, Long and Float, those are object-wrapped value classes for the intrinsic types.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mike Birken

Joined: Dec 28, 2001
Posts: 20
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

Joined: Dec 06, 2001
Posts: 138
So is an Int an Object?
Matthew Haynes

Joined: Feb 04, 2002
Posts: 6
Int is invalid
Most of the wrapper classes follow the naming convention of "primitive name starting with a capital". Eg:
primitive/wrapper class
The two exceptions are integers and characters which are:
I agree. Here's the link:
subject: Very Basic Question
It's not a secret anymore!