Java long Data Type With Example

The long data type in Java

The long is one of the primitive data types in Java, among the eight available types. This is a numeric data type like byte, int etc.

See an example of Long variable

A few points to know about the Java long data type:

  • Takes 64 bits or eight bytes memory.
  • The long is a numeric data type.
  • The default value of a long type variable is 0.
  • The minimum value of the long 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

As you run the code, the output will be:


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.