The Long Data Type Variable in Java Programming
Java Basic Concepts
In this chapter we are going to learn about the long data type variable of Java programming. We will go through some examples and take a quiz after that.
What is Long Variable
The long data type is the largest integer data type available in Java. It can store values within the range -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. The long data type can be useful while working with larger integer numbers in a java program.
Syntax of Declaring Long Variable in Java
Here long is used for declaring Long data type and variable_name is the name of variable (you can use any name of your choice for example: a, b, c, alpha, etc.) and ; is used for line terminator (end of line).
Now let's see some examples for more understanding.
Declare a long variable x.
Declare a long variable x to assign a long value 1024.
long x = 1024;
Declare 3 long variables x, y and z in a single line.
long x, y, z;
Declare 3 long variables x, y and z to assign the long value 4297, 670 and 8531 respectively in a single line.
long x=4297, y=670, z=8531;
Declare a long variable x and assign the long value 180 in the second line.
long x; x = 180;
Declare a long variable x and assign the long value 7654 and change its value to 548 in the next line.
long x = 7654; x = 548; // now the new value of x is 548