digitization, transformation, binary

Abstract Class Number in Java

The Abstract class Number is the superclass for all numerical primitive types (for all of the classes that provide
object wrappers for primitive numeric values)like- Byte, Short, Integer, Long, Float, Double.

Wrapping a primitive value is useful when you need to treat such a value as an object. For example, there are a number of utility methods that take a reference to an Object as one of their arguments. We cannot specify a primitive value for one of these arguments, but we can provide a reference to an object that encapsulates the primitive value.

This class defines the conversion functions that these classes implement. The Number class defines six methods that must be implemented by its subclasses: byteValue(), shortValue(), intValue(), longValue(), floatValue(), and doubleValue(). This means that a Number object can be fetched as a byte, short, int, long, float, or double value,
without regard to its actual class.

The structure of Number class is as follows:


public abstract Class java.lang.Number extends java.lang.Object implements java.io.Serializable{
//Constructor
public Number();
//Methods:
public abstract byte byteValue();
public abstract double doubleValue();
public abstract float floatValue();
public abstract int intValue();
public abstract long longValue();
public abstract short shortValue();
}
 

The details of the class structure are given as follows:

public abstract byte byteValue();

public abstract byte byteValue() method returns the value of this object as a byte. If the data type of the value is not a byte, rounding may occur.

This method returns the value of this object as a byte.

public abstract double doubleValue();

public abstract double doubleValue() method returns the value of this object as a double. If the data type of the value is not double, rounding may occur.

READ  Class DatagramSocket in Java

This method returns the value of this object as a double.

public abstract float floatValue();

public abstract float floatValue() method returns the value of this object as a float. If the data type of the value is not float, rounding may occur.

This method returns the value of this object as a float.

public abstract int intValue();

public abstract int intValue() method returns the value of this object as an int. If the type of value is not an int, rounding may occur.

This method returns the value of this object as an int.

public abstract long longValue();

public abstract long longValue() method returns the value of this object as a long. If the type of value is not a long, rounding may occur.

This method returns the value of this object as a long.

public abstract short shortValue();

public abstract short shortValue() method returns the value of this object as a short. If the type of value is not a short, rounding may occur.

This method returns the value of this object as a short.
Apart from these methods the Number class also has inherited methods from class- Object. They are as follows:

  • clone()
  • finalize()
  • hashCode()
  • notifyAll()
  • wait()
  • wait(long, int)
  • equals(Object)
  • getClass()
  • notify()
  • toString()
  • wait(long)

LEAVE A REPLY

Please enter your comment!
Please enter your name here