When we work with numbers most of the time it is that we work with primitive data types.
int x=7347;
double y=6.8879;

However sometimes it occurs that a user cant use these data types so in that case. A user can use objects through the wrapper classes.
Actually what does the wrapper class does is that it “wraps” the data types in an object. The compiler then converts these data types to objects and this is called boxing. Similarly if we need a primitive data type instead of an object,compiler will do that(convert object to primitive data type) and this process is called unboxing.
[java] public class mul
public static void main(String args[])
Integer i=10; /*boxing of int to Integer object*/
i=i*4; /*unboxing of Integer object to int */


The Numbers class is contained ssin java.lang package.

Number Methods Methods Description
1. compareTo() Compares this Number object to the argument.
2. ceil() Returns the smallest integer that is greater than or equal to the argument. Return type is double.
3. floor() Returns the largest integer that is less than or equal to the argument. Return type is double.
4. rint() Returns the integer that is closest in value to the argument. Return type is double.
5. abs() Returns the absolute value of the argument.
6. round() Returns the closest integer(can be long depending on the data type).
7. min() Returns smaller of the two arguments.
8. max() Returns larger of the two arguments.
9. exp() Returns exponent of the natural log.
10. pow() Returns the value of the first argument raised to the power of the second argument.
11. log() Returns the logarithmic value of the argument.
12. sqrt() Returns square root of the argument.
13. sin() Returns the sine of the specified double value.
14. cos() Returns the cosine of the specified double value.
15. tan() Returns the tangent of the specified double value.
16. acos() Returns the arccosine of the specified double value.
17. asin() Returns the arcsine of the specified double value.
18. random() Returns a random number.
19. toRadians() Converts argument to radian.

Facebook Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.