HomeJava

Java for Testers – double data type

Java for Testers – double data type

<<Previous Post                    << Complete Tutorial>>                        Next Post>>

In the previous article, I have explained about int data type in Java.

In this article, I am going to explain and practically demonstrate the double data type in Java.

Java for Testers – double data type

Decimal values like 9.36 etc. can be stored into a variable which is declared with double data type.

For example:

double b = 9.63;

In the above example, we have declared the variable b with double data type, and hence we are able to store the decimal values like 9.36 into the variable.

Follow the below steps for practically implementing double data type in Java:

1) Let’s create a Java program and create a Demo class as shown below:

Note: If you are not aware of creating a Java project and a Class in Java, refer to our previous article – Creating a Java project in Eclipse IDE

Print statements - Java project

2) Inside the main() method, let’s create a variable, declare the variable with double data type and assign the variable with a decimal value 9.36 as shown below:

Using Data Types Java - double

3) Now print the value stored in the variable by printing the variable using the print statement as shown below:

Using Data Types Java - print double

4) Save the Project and click on the ‘Run’ button.

Observe that the Program got executed and the decimal value 9.36 stored in the variable b got printed as shown below:

Using Data Types Java - double printed

Copy the above-explained code from the below section:

public class Demo {

	public static void main(String[] args) {
		
		double b = 9.36;
		
		System.out.println(b);
		
	}

}

Before concluding this article, I would like to give more details about the double data type in Java.

There is one more data type, which can store the decimal values similar to double data type i.e. float data type.

The size of the double data type is double the float data type.

Technically speaking double data type is a double-precision 64 bit IEEE 754 floating point and whereas float data type is single-precision 32 bit IEEE 754 floating point.

In general, we use double data type moreover float data type for storing the decimal values.

I will demonstrate float data type in the upcoming articles.

Here concludes this article.

In the next article, I will explain and demonstrate the char data type in Java.

Next Steps:

  • > To learn more about Java, continue to the next post (Click on Next Post link below)
  • > Check complete Java Tutorial Contents here (Click here)

Please leave your questions/comments/feedback below:

Happy Learning ?

Arun Motoori (www.QAFox.com)

On a mission to help the Testing Community in all possible ways.

<<Previous Post                    << Complete Tutorial>>                        Next Post>>

Comments (0)

Leave a Reply

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

For FREE Testing Tutorials & Videos

X
Open chat
Contact Us on Whatsapp