Table of content

What is long in Java?

The long keyword is a data type that can store whole numbers. The long data type is 8 bytes.

The long data type is a 64 bit two's complement integer. The range of long data type is -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.

The minimum value is -9,223,372,036,854,775,808(-263) and the maximum value is 9,223,372,036,854,775,807(263). The default value is 0.

The long data type is used when the user needs a range of values more than those provided by the int data type.

When declaring the long data type, the number should be terminated by L. For example long x = 4,50,000L; long y = -8,78,080;

The example below illustrates how to add two long variables.

public static void main(String args[]) {
  long a = 456728976231 L;
  long b = 982563646274 L;
  long sum = a + b;
  System.out.println("The sum of two long variables is = " + sum);
}

The output is

The sum of two long variables is = 1439292622505
0 results
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions