• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

Java Numbers Class

by admin

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

Example:

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.

Example:

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
        System.out.println(x);
    }
}

output

49

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.

Filed Under: Java

Some more articles you might also be interested in …

  1. Java Character Class
  2. Java Interfaces
  3. How to format Output and Input in Java
  4. Java Classes and Objects
  5. Java Methods
  6. Java Field and Method Modifiers
  7. Using ‘final’ Keyword in Java
  8. JAVA Installation
  9. Java Access Modifiers
  10. User-defined Exceptions in Java

You May Also Like

Primary Sidebar

Recent Posts

  • raw: command not found
  • raw Command Examples in Linux
  • rankmirrors Command Examples in Linux
  • radeontop: command not found

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright