Categories: Keyword in Java

The double keyword in Java programming language

The double keyword in java programming language

In this tutorial,  we will discuss about the double keyword in java programming language

In Java programming language, double is a keyword is used to declare a floating point variable as a numeric type. A double value can hold a 64-bit floating point number. Double is a primitive data type in Java language.

Declaration of variable

Syntax for double variable

double <variable_name>=<float_value>;

Example of variable

double amount_Currency=34.98766;

The double keyword can be used to declare a return type of method in java.

Declaration of method

Syntax for double as a method

<access_modifier> <return_type> <method_name>;
{
return <method_name>;
}

Example

public double getBalance()
{
return myBalance;
}

Example double method within class

public class Example _double{  // this is a class in java
public static void main(String args[]){ // this is a main method in java
}
public double add(){  // this is a method as double;
//return values
}
}


program 1

public class Double_Keyword{
        public static void main(String args[]){
            double d1=45.87; //double keyword used as variable
            double d2=53.6;
            double result=d1+d2;
            System.out.println("The result is :"+result);
                    }

            }

 

When the above code is compiled and executed, it will produce the following results

The result is :99.47

 

Program 2

public class Double_Keyword1{
        public static void main(String args[]){
        add(34.56f,67.87f);
        }
        static double add(double a,double b){
//double keyword is used with method as return type
        double result=a+b;
        System.out.println("The result is :"+result);
        return result;
                    }

            }

 

When the above code is compiled and executed, it will produce the following results

The result is :102.43

 

 

There are other Java language keywords that are similar to the this keyword

The byte keyword in Java

The short keyword in Java

The int keyword in Java

The long keyword in Java

The float keyword in Java

The boolean keyword in java

The char keyword in Java

The void keyword in Java

 

Suggested for you

Java language Keywords

 C++ languageKeywords

C language Keywords

 Python language Keywords

The float keyword in Java programming language
The boolean keyword in Java programming language
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Share
Published by
Karmehavannan

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

1 month ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

1 month ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

9 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

9 months ago