Results 1 to 2 of 2

Thread: to Float or float? [Resolved]

  1. #1

    Thread Starter
    Hyperactive Member CaptainPinko's Avatar
    Join Date
    Jan 2001
    Location
    London, Ontario, Canada
    Posts
    332

    Lightbulb to Float or float? [Resolved]

    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.
    Last edited by CaptainPinko; Sep 27th, 2001 at 10:58 AM.
    "There are only two things that are infinite. The universe and human stupidity... and the universe I'm not sure about." - Einstein

    If you are programming in Java use www.NetBeans.org

  2. #2
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width