• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java wrapper classses

 
Mark Mokris
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Each of the Java numeric wrapper classes seem to have two constants: NEGATIVE_INFINITY and POSITIVE_INFINITY. What do these mean, and what are they for? How might they be used?
Another question. I can see how the wrapper classes can be used to convert among numbers, strings, and primitive data values. Is there any other real use for them?
Thanks,
Mark
 
Jon Strayer
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mark Mokris:
Each of the Java numeric wrapper classes seem to have two constants: NEGATIVE_INFINITY and POSITIVE_INFINITY. What do these mean, and what are they for? How might they be used?

Floating point math is a bit different from interger math. If you divide by zero using integer math you get an exception. If you divide by zero with floating point values you get an infinity back. You need to be able to test your answer to see if you hosed it up. That's what the constants POSITIVE_INFINITY and NEGATIVE_INFINITY are for. NaN stands for Not a Number. That's what you get when you try to take the square root of a negative number (for example).

Another question. I can see how the wrapper classes can be used to convert among numbers, strings, and primitive data values. Is there any other real use for them?
Thanks,
Mark

You can also put them into a container. You can't do that with the primitives.
 
Greg Charles
Sheriff
Posts: 2984
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right, what Jon said. The main use of wrapper classes is to use primitives where objects are required, like as elements of a Vector, ArrayList, or any of the collections.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic