The moose likes Beginning Java and the fly likes Java wrapper classses Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Java wrapper classses" Watch "Java wrapper classses" New topic
Author

Java wrapper classses

Mark Mokris
Ranch Hand

Joined: May 08, 2002
Posts: 61
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

Joined: Dec 04, 2002
Posts: 133
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.


Jon
Greg Charles
Bartender

Joined: Oct 01, 2001
Posts: 1855

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.
 
 
subject: Java wrapper classses
 
Threads others viewed
Usage of Wrapper Classes
Thread t = primitive value?
immutable classes
clarify my doubt
JAX-RPC DII or Stub based client
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture