All About Class Double in Java

Spread the love
  • 1

 Class Double in Java
Class Double in Java

Class Double in Java:

Double class i n java wraps up a value of primitive type double in an Object. An Object of type Double contains a single field whose type is double.

Since the double values have a finite accuracy they can’t get arbitrarily close to zero. Also double can represent non real numbers.Like
Double can represent negative zero(-0.0).Dividing a positive number by negative zero gives NEGATIVE_INFINITY

Class Double in Java

If we divide a number by positive zero(0.0) we get POSITIVE_INFINITY
NaN stand for Not a Number(An undefined value) like-

  1. Square root of a negative number.
  2. zero or divide by zero.
These operations stop real number calculation to throw an Exception by simply giving NaN as output.


The structure of class Double is given below:

public final class java.lang.Double extends java.lang.Number{
//Member elements
public final static double MAX_VALUE;
//MAX_VALUE=1.79769313486231570 e to the power +308
public final static double MIN_VALUE;
//MIN_VALUE=4.94065645841246544 e to the power -324
public final static double NAN;
//NAN is 0 divided by 0 . Not a number
public final static double NEGATIVE_INFINITY;
//produced when a negative number is divided by 0 like -10/0
public final static double POSITIVE_INFINITY;
//produced when a positive number is divided by 0 like 10/0
public Double(double value);
//Constructs a newly allocated Double object that represents the primitive double argument.
public Double(String str);
//Constructs a newly allocated Double object that represents the floating point value of double represented by 
//String str.The string is converted to a double value by valueOf() method.This method may throw 
//NumberFormatException if the string does not contain a parsable number.
public static long doubleToLongBits(double value);
public static boolean isInfinite(double value);
public static boolean isNaN((double value);
public static double longBitsToDouble((long bits);
public static String toString(double value);
public static Double valueOf(String str);
public double doubleValue();
public boolean equals(Object obj);
public float floatValue();
public int hashCode();
public int intValue();
public boolean isInfinite();
public boolean isNaN();
public long longValue();
public String toString();

class double

We can also test if a value ‘x’ is of the type double or is infinity or undefined by calling the static methods:


class double

These method returns boolean value to indicate if the given value is Infinite or NaN.

Double.NaN when operated with rational operators such as == always give us false,no matter what value of x is given.


Both will return false.
Math.random() function returns a double value.
we need to work with range to trim to our required value.

int max=6;
int min=1;
int range=max-min+1;
int rand=(int)(Math.random()*range+min);
Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

Spread the love
  • 1


  1. Do you have any kind of suggestions for creating
    short articles? That’s where I constantly battle as well as I just finish up staring vacant screen for
    long time.


Please enter your comment!
Please enter your name here