CaptainPinko
Sep 17th, 2001, 10:49 AM
When would I use the Float or Double objects (java.lang...) as opposed to their respective primitive datatypes? And are these classes what people call "wrapper classes"? Any ideas, comments, or suggesions are welcoming.
Dillinger4
Sep 17th, 2001, 01:21 PM
yes these classes are called wrapper class which are found in the java.lang package. off the top of my head they are Integer, Short,Float Double, Long, Boolean and i think Byte.
Since primative types are not objects they cannot be accessed or
manipulated using methods. Hence the creation of the wrapper classes.
The wrapper classes are really just used to add additional functionality to their corresponding primative types. At least from what i know. The number class is the abstract super class of the Integer, Byte ,Long,Float, Double, Short wrapper classes. It provides conversion funcitons that are inherited by the wrapper classes. A short look at the API docs will give you a list of these functions. There are not many though.
As for the additional functionality here is a quick example.
If you wanted find an integers equivalent hexadecimal value
you could use the public static String toHexString(int i) method. This would give you a String representation. Or you could use public static Integer valueOf(String s, int radix). I think if you use this last method you could take the Integer object returned by this method and use the public abstract intValue() method inherited from the Number class to convert the Interger Object to a integer primative type.
But the whole point of the wrapper classes in my opinion is added functionality and manipulation. Hoped i helped a little.
:)