The long data type in Java
The long is one of the primitive data types in Java, among the eight available data types. This is a numeric data type like byte, int etc.
See an example of Long variable
TheJava long data type:
- Takes 64 bits or eight bytes memory.
- The Java long is a numeric data type.
- The default value of a Long variable is 0.
- The minimum value of the long, Java data type can be -9,223,372,036,854,775,808.
- The maximum value of the long type can be 9,223,372,036,854,775,807.
- Other numeric data types include the byte, short, int while the float and double with single and double precision, respectively.
An example of the Long data type
The following is a Java long type example. See the example online by clicking the link below:
See graphic of example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
public class variable_example {
public static void main(String []args) {
long a;
long b=–100000000;
a=1000000000;
System.out.println(a); // Java Variable example
}
}
|
As you run the code, the output will be:
1000000000
In the above example, you can see a long variable is declared by using the keyword: long followed by the variable name. For the demo to illustrate the long type, we have used two long type variables.
The first variable is assigned a value at the time of declaration while the other long variable’s value is assigned after the declaration. Finally, the variable’s value is printed by using the Java statement.
Also see – Data types in Java
Leave A Comment?