# Java wrapper classses

Mark Mokris

Ranch Hand

Posts: 61

posted 14 years ago

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

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

posted 14 years ago

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).

You can also put them into a container. You can't do that with the primitives.

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*