The long keyword in Java programming language
- Home
- Keyword in Java
- The long keyword in Java programming language
- On
- By
- 0 Comment
- 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
static keyword in Java language
extends keyword in Java language
Suggested for you
Usage of final keyword in Java
Finally keyword in Java language