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.
the syntax of the long keyword in variable
int <variable_name> <long_value>;
Example of long keyword
long amount; = 2345;
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
the syntax of the long keyword in variable
access_modifier long method_name(){ return value;//return statement }
Example of the long keyword in declaring a method
public long gerHeight(){ }
Above method is a long method which returns any value
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
static keyword in Java language
extends keyword in Java language
Suggested for you
Usage of final keyword in Java
Finally keyword in Java language
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…
Java program to check odd or even using recursion In this tutorial, we discuss a…