Categories: Keyword in Java

The long keyword in Java programming language

The long keyword in Java programming language

In this tutorial, we will learn about the long keyword in java programming language

long is a Java keyword which is used to declare a variable as a numeric type. A long value can hold a 64-bit integer number which ranges from -263 to 263-1.

Declaration variable

the syntax of the long keyword in variable

int <variable_name> <long_value>;

Example variable

Example of long keyword

long amount; = 2345;

 

The long keyword in Java

program 1

public class long_Keyword{
        public static void main(String args[]){
            long l1=10012; //long keyword is used as variable
            long l2=11011;
            long result=l1+l2;
            System.out.println("The result is :"+result);
                    }

            }

 

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

The result is :21023

 

 

The long keyword can be used to declare return type method in Java

Declaration of method

the syntax of the long keyword in variable

access_modifier long method_name(){
return value;//return statement
}

Example method

Example of the long keyword in declaring a method

public long gerHeight(){

}

Above method is a long method which returns any value

Example long method within the class

public class Example _long{  // this is a class in java
public static void main(String args[]){ // this is a main method in java
}
public long add(){  // this is a long method which returns value;
}
}

program 2

public class long_Keyword1{
        public static void main(String args[]){
            add(34656,45634);
        }
            static long add (long l1,long l2){ 
            //long keyword is used to method as return type
            //long keyword is used as parameter
            long result=l1+l2;
            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 :80290

 

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

 byte keyword in Java

 short keyword in Java

 int keyword in Java

long keyword in Java

 float keyword in Java

char keyword in Java

 void keyword in Java

try keyword in Java

Catch keyword in Java

implements keyword in java

public Key words in Java

static keyword in Java language

Volatile Keyword in Java

Transient keyword in Java

Package keyword in Java

class keyword in Java

boolean keyword in Java

break keyword in Java

do keyword in Java

double keyword in Java

This keyword in Java

final keyword in Java

switch keyword in Java

interface keyword in java

extends keyword in Java language

 

Suggested for you

 Java language Keywords

C language Keywords

 Python language Keywords

keywords in C language

Usage of final keyword in Java

Usage of this keyword in Java

Finally keyword in Java language

 

 

The short keyword in Java programming language
Keywords 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.

Recent Posts

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago

Java program to check odd or even using recursion

Java program to check odd or even using recursion In this tutorial, we discuss a…

2 months ago