×

Java Double Keyword

  • In java primitive data types, we have two different types of data types which are Boolean and floating-point data types.
  • In floating data type again we have four types which are integers, float, double, long.
  • So, now in this article we are going to learn about the primitive data type which is a double keyword or data type.
  • The name of the keyword double is evolved because of the float data type this is because the float capacity is 4 bytes whereas double is 8 bytes which is twice or double of float.
  • The double keyword is also known to be a precise data type or keyword as it can store the large values of the integers while declaring using double.
  • Double keyword or data type stores the real numbers which includes integers, rational and irrational, natural numbers, whole numbers.
  • So, the double stores the double precision of 64-bits.
  • The variables and the methods are being implemented using the keyword double or keyword data type.
  • The decimal numbers are generally initialized or declared using the double keyword or data type.

Points to remember:

  • The range of the double keyword is varied from the values 4.940656458412e-324d to1.79763134862e+308d (positive and negative).
  • Double keyword holds the default value that is 0.0d.
  • Default storage capacity or default size of the keyword double is taken as 8 bytes.
  • The double keyword cannot be implemented for precise values like currency because it effects the approaching way of assigning values through double keyword.

Syntax of Java Double Keyword

double variable name.

EX: double a; doubleraju; etc.

Here in above example double is the keyword and a, raju are variables name.

We can also declare multi variables for a keyword double at a time that is

EX: double variable 1, variable 2,variable3.

Java Double Keyword Examples

Example 1:

Simple example program to declare the variable using double keyword.


public class DblEx1 {  


    public static void main (String [] s) {  


        double R=9.5;
        System.out.println("R: "+R);
    }     
}  

Output:

R:9.5

Example 2:

The integer value of a variable is assigned to the double data type in this program. The providing of the value is called typecast integer to double. So that it shows the similar values in decimal form.

public class DblEx2 {  


    public static void main (String [] s) {  


        double D1=3;
        double D2=17;
        System.out.println("D1: "+D1);
        System.out.println("D2: "+D2);
    }  
}  

Output:

D1: 3.0
D2: 17.0

Example 3:

In this example program we will test the double keyword by assigning bigger values.

public class DblEx3 {  


    public static void main (String [] s) {  


        double Dee 1=78.8653457874857.
        double Dee 2=5.676793847579876.
        System.out.println("Dee1: "+Dee1).
        System.out.println("Dee2: "+Dee2).


    }  


}  

Output:

Dee1: 78.8653457874857.  
Dee2: 5.676793847579876

Example 4:

Assigning the float value to decimal variable for testing the working of double keyword.

public class DblEx4 {  


    public static void main (String [] s) {  


        double mah1=87.11f;
      double mah2=39f;
        System.out.println("mah1: "+mah1);
        System.out.println("mah2: "+mah2);


    }  


}  

Output:

Mah 1: 87.11000015258789
Mah 2: 39.0


Example 5:

Assigning the maximum range of decimal value using double data type.

public class DblEx5 {  


    public static void main (String [] s) {  


        double Dav1=4.94065645841246544e-324d.
        double Dav2=1.79769313486231570e+308d;
        System.out.println("Dav1: "+Dav1);
        System.out.println("Dav2: "+Dav2);
    }  
}  


Output:

Dav1: 4.9E-324
Dav2: 1.7976931348623157E308

Example 6:

Here this example provides the values the in scientific notation using double keyword.

public class DblEx6 {  


    public static void main (String [] s) {  


        double Raj1=1873.2;
        //providing similar value in scientific notation  
        double Raj2=1.8732e3;
        System.out.println("Raj1: "+Raj1);
        System.out.println("Raj2: "+Raj2);
    }  


}  

Output:

Raj1: 1873.2
Raj2: 1873.2

Example 7:

We can also create method that returns the type of integer using double keyword.

public class DblEx7 {  
    public double display (double hight)  
    {  
        return hight;
    }  


    public static void main (String [] s) {  


        DblEx7 g=new DblEx7();
        System.out.println(g. display(98.5));  
    }     
}  

Output:

98.5

Example 8:

Example program for Double and integer interaction in java programming language.

public class DblDemo1{
   public static void main (String [] args) {
       int l = 6;
       double Dbl1 = 9;
       double Dbl2 = k*7.0;
       System.out.println(Dbl1);
       System.out.println(k*Dbl1);
       System.out.println(Dbl);
   }
}

 output:

6.0
9.0
14.0

Related Topics

Java Interface Keyword

An interface is also known as the blueprint in Java. It has constants of static values and methods of abstraction. The interface is a mechanism used by Java to declare...

3 minutes read.

Convert milliseconds to date in Java

In Java, we frequently need to convert milliseconds into Dates with several formats, including dd MM yyyy and dd MM yyyy HH:mm:ss:SSS Z, among others. The Date class is one of the most...

4 minutes read.

Types of Logical Operators in Java

In this tutorial, we are going to study logical operators. A logical operator is an operator that accomplishes a logical operation that is to connect two or more operations. These...

5 minutes read.

Java Math tanh() Method

The tanh() method of Java Math class returns the hyperbolic tangent of the specified double value. Syntax: public static double tanh(double x) Parameters: The parameter ‘x’ represents the number whose hyperbolic tangent is to...

2 minutes read.

Java Integer max() method

The max() method of Integer class returns the greater of two int values. It returns the same result as by calling Math.max. Syntax public static int max(int a, int b) Parameters The parameters ‘a’...

2 minutes read.

How to initialize string array in Java

In this tutorial, we will learn how the string array is initialized in java. The initialization of string array in the java by using the NEW (it creates the object for...

3 minutes read.

Java extend multiple classes

In Java, what does extend mean? One of several Java inheritance keywords is extended, meaning we pass all or most of the Parent class's characteristics through to the Child class. The...

3 minutes read.

Class vs Object in Java

Java : Java is a pure object oriented language. It was introduced by James Gosling in the year 1995. The first public implementation of java was done by sun micro systems...

7 minutes read.

How to Convert String to long in Java

How to Convert String to long in java It is used when you want to perform the mathematical operation on the String which contains long number then the conversion from String...

4 minutes read.

Java Single Linkedlist

Like arrays, linked lists are a type of linear data structure. Unlike arrays, which store each element in the same location, linked lists employ pointers to connect the elements together. In...

25 minutes read.

Java inheritance with Example

Java inheritance Java inheritance is a mechanism in which a child object acquires all the properties and behaviors of a parent object. It helps in reusing the code and establishes...

7 minutes read.

How to check version of java in Linux

Java is one of the most famous and thoroughly utilized programming tongues from one side of the world to the other. On the off chance that you are a Java...

2 minutes read.

Big Decimal class in Java

The fairly Big pretty Decimal class provides operations for arithmetic, rounding, comparison and format conversion in a sort of big way. It can handle generally large and very small floating-point...

6 minutes read.

Java RMI

What is RMI in Java? A framework for developing distributed Java applications is provided by the RMI (Remote Method Invocation) API. An object can call methods on an object running in...

4 minutes read.

Java Thread class

Thread class The thread represents a part of the process. Every process can have multiple associated threads in which every thread may execute the same or different job. By default, each thread assigns...

16 minutes read.

Kotlin Vs Java

Kotlin Vs Java There are many languages available for Android development. Java is the official language for android development but Kotlin is becoming popular nowadays. This article discusses both of these...

4 minutes read.

BigDecimal toString() in Java

BigDecimal is a Java class that is a part of the java.math package and the java.base module. It implements the ComparableBigDecimal> interface and extends the Number class. The BigDecimal class...

3 minutes read.

How to take Array Input in Java

In this tutorial, we will learn about how to take array input in Java. So, before taking inputs let us know what an array is first. Array: An array is a collection...

10 minutes read.

Java gc()

Garbage collection Java language provides different ways to perform the task of memory management. In Java, objects are declared and assigned references. Once lifeof an object is completed it is dereferenced...

4 minutes read.

Timestamp Operation in Java

JDBC escape syntax is supported by Timestamp's formatting and parsing functions. Additionally, it adds support for fractional seconds values for SQL TIMESTAMP.java.util.Date is wrapped in a lightweight wrapper that enables...

3 minutes read.