Java Numbers Class

Numbers are primitive data types such as int ,float ,long ,double.

int a = 2000;
float acg = 11.18;
double mask = 0acf;

Java give wrapper classes.
All the wrapper classes (Integer, Long, Byte, Double, Float, Short) are subclasses of the abstract class Number.
Following is an example of setting1 and setting2 −
public class Test {

   public static void main(String args[]) {
      Integer x = 25; // setting1 int to an Integer object
      x =  x + 24;   // setting2 the Integer to a int


When x is assigned an integer value, the compiler setting1 the integer because x is integer object. Later, x is setting2 so that they can be added as an integer.

Number Methods

  • compareTo()Compares this Number object to the argument.

  • equals()This method Determines whether this number object is equal to the argument.

  • valueOf() Returns an Integer object holding the value of the specified primitive.

  • toString()Returns a String object representing the value of a specified int or Integer.

  • xxxValue()Converts the value of this Number object to the xxx data type and returns it.

  • abs()Returns the absolute value of the argument.

  • ceil()Returns the smallest integer that is greater than or equal to the argument. Returned as a double.

  • parseInt()This method is used to get the primitive data type of a certain String.

  • floor()Returns the largest integer that is less than or equal to the argument. Returned as a double.

  • round()Returns the closest long or int, as indicated by the method's return type to the argument.

  • rint()Returns the integer that is closest in value to the argument. Returned as a double.

  • min()Returns the smaller of the two arguments.

  • max()Returns the larger of the two arguments.

  • log()Returns the natural logarithm of the argument.

  • pow()Returns the value of the first argument raised to the power of the second argument.