Java.lang.Double Class

Java Double Class

The Double class in the Java.lang package encapsulates a value of the primitive type double in an object. A single field of type double is included in a Double object. This class also has methods for converting a double to a String and a String to a double, as well as other essential constants and methods for working with doubles. Let us now begin with Java.lang.Double Class.

 

Class declaration

The declaration of java.lang.Double class is:

 

public final class Double
  extends Number
    implements Comparable<Double>

 

 

Fields

 

S.N Fields & Description
1. static int BYTES
The number of bytes used to represent a double value.
2. static int MAX_EXPONENT
Maximum exponent a finite double variable may have.
3. static double MAX_VALUE
A constant holding the largest positive finite value of type double, (2-2-52)·21023.
4. static int MIN_EXPONENT
Minimum exponent a normalized double variable may have.
5. static double MIN_NORMAL
A constant holding the smallest positive normal value of type double, 2-1022.
6. static double MIN_VALUE
A constant holding the smallest positive nonzero value of type double, 2-1074.
7. static double NaN
A constant holding a Not-a-Number (NaN) value of type double.
8. static double NEGATIVE_INFINITY
A constant holding the negative infinity of type double.
9. static double POSITIVE_INFINITY
A constant holding the positive infinity of type double.
10. static int SIZE
The number of bits used to represent a double value.
11. static Class<Double> TYPE
The Class instance representing the primitive type double.

 

java.lang.Double Methods

 

The java.lang.Double class has a number of methods which are listed below:

 

Member Methods

 

S.N Methods & Description
1. byte byteValue()
Returns the value of this Double as a byte after a narrowing primitive conversion.
2. static int compare(double d1, double d2)
Compares the two specified double values.
3. int compareTo(Double anotherDouble)
Compares two Double objects numerically.
4. static long doubleToLongBits(double value)
Returns a representation of the specified floating-point value according to the IEEE 754 floating-point “double format” bit layout.
5. static long doubleToRawLongBits(double value)
Returns a representation of the specified floating-point value according to the IEEE 754 floating-point “double format” bit layout, preserving Not-a-Number (NaN) values.
6. double doubleValue()
Returns the double value of this Double object.
7. boolean equals(Object obj)
Compares this object against the specified object.
8. float floatValue()
Returns the value of this Double as a float after a narrowing primitive conversion.
9. int hashCode()
Returns a hash code for this Double object.
10. static int hashCode(double value)
Returns a hash code for a double value; compatible with Double.hashCode().
11. int intValue()
Returns the value of this Double as an int after a narrowing primitive conversion.
12. static boolean isFinite(double d)
Returns true if the argument is a finite floating-point value; returns false otherwise (for NaN and infinity arguments).
13. boolean isInfinite()
Returns true if this Double value is infinitely large in magnitude, false otherwise.
14. static boolean isInfinite(double v)
Returns true if the specified number is infinitely large in magnitude, false otherwise.
15. boolean isNaN()
Returns true if this Double value is a Not-a-Number (NaN), false otherwise.
16. static boolean isNaN(double v)
Returns true if the specified number is a Not-a-Number (NaN) value, false otherwise.
17. static double longBitsToDouble(long bits)
Returns the double value corresponding to a given bit representation.
18. long longValue()
Returns the value of this Double as a long after a narrowing primitive conversion.
19. static double max(double a, double b)
Returns the greater of two double values as if by calling Math.max.
20. static double min(double a, double b)
Returns the smaller of two double values as if by calling Math.min.
21. static double parseDouble(String s)
Returns a new double initialized to the value represented by the specified String, as performed by the valueOf method of class Double.
22. short shortValue()
Returns the value of this Double as a short after a narrowing primitive conversion.
23. static double sum(double a, double b)
Adds two double values together as per the + operator.
24. static String toHexString(double d)
Returns a hexadecimal string representation of the double argument.
25. String toString()
Returns a string representation of this Double object.
26. static String toString(double d)
Returns a string representation of the double argument.
27. static Double valueOf(double d)
Returns a Double instance representing the specified double value.
28. static Double valueOf(String s)
Returns a Double object holding the double value represented by the argument string s.

 

Methods inherited

 

This class inherits the methods of the following class:

  • java.lang.Object
  • java.lang.Number

 

To open the online compiler click here.

 

Also Read: Java – If-Else

Leave a Reply

Your email address will not be published. Required fields are marked *