×

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 Arrays Fill

We may use the Arrays.fill () function to fill a whole array or a subset of it. Arrays.fill () may fill both 2D and 3D arrays. Syntax: Arrays.fill(boolean[] fillArr, int fromIndex, int toIndex, boolean val )   Parameters: The array to be filled...

4 minutes read.

Web Crawler in Java

In this article, you will be acknowledged with what a web crawler in java is and what are its functions. You will also be able to understand where to implement...

4 minutes read.

Java Exception Propagation

Java Exception Propagation When an exception is being thrown from the peak of the stack and not getting caught, it runs down the stack to the previous method, which is sitting...

3 minutes read.

Polygonal Number in Java

What does a Java Polygonal Number Mean? In mathematics, a polygonal number refers to a number that is expressed through dots or pebbles arranged in a regular polygonal pattern. Alphas are...

4 minutes read.

The Diamond Operator in Java 7

The Diamond operator is a comparatively recent Java operator originally developed in JDK 7 to enhance type identification and eliminate boilerplate Java code. The Diamond operator is characterized by a...

2 minutes read.

Java class class

Java Class class instances are an executing Java application's implementation of the classes and interfaces. As well as, every Array is indeed an object that is common for all Arrays...

6 minutes read.

How to Convert String to Object in Java

How to Convert String to Object in Java The Object is the super class of all classes. So you can assign a string to Object directly. There are two methods to...

3 minutes read.

How to add 4 Years to the Current Date in Java?

In this tutorial, we will learn how to add 4 years to the local or current date in Java language. We will begin our topic with basic concepts and would...

2 minutes read.

Hierarchy of operators in Java

Operators are the most frequently used terminology in any area of programming, and it helps in various approaches to efficiently solve daily life problems by computer programming. The simple addition of...

4 minutes read.

Virtual Function in Java

In the Operated Oriented Programming language, a virtual function or virtual method is a collection of functions that overrides the functionality of a function in an inheriting class with the same...

4 minutes read.

Java array list remove time complexity

Java: We know that java is one of the programming languages. The main feature of java which is not in C or object oriented programming language is platform independence. Not only the...

7 minutes read.

String vs StringBuilder

String vs StringBuilder In this section, we will discuss the comparison between Java String and StringBuilder class. String In Java, a string is treated as an object that represents a sequence of characters....

4 minutes read.

How to create array of objects in Java

Java is an object-oriented programming language therefore everything in Java is based on objects and classes. Array is a data structure that holds data of similar type and dynamically creates...

4 minutes read.

Java Destructors

Before knowing about Java destructors, let us know about constructors. If we understand the concept of the constructor, we can easily understand about destructor and also, we will get an...

3 minutes read.

Compare Two Times in Java

Definition The compareTo() function of the LocalTime class is used to compare times. The class's compareTo() method compares two LocalTime objects. Here we have two objects that have to be compared: the...

4 minutes read.

Switch Case Program in Java

Switch Case Program in Java The switch case program in Java controls which code snippet gets executed on the basis of the value of the expression mentioned in the switch statement....

22 minutes read.

Thread Concept in Java

What is a Thread? A subprocess that is lightweight in Java is known as a thread. It is the smallest unit of a process. For the running of multiple tasks parallelly...

3 minutes read.

Difference between = = and equals ( ) 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...

6 minutes read.

How to encrypt password in Java

Every software program needs a username and password to identify a legitimate user. A username can be any number of things, including an email address or a string of characters....

6 minutes read.

Java Trim

Leading and leaving spaces are removed by the built-in Java String trim() method. Space seems to have the Unicode element of "x0040." Java trim() function looks for all of these...

3 minutes read.