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 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

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.


Also see – Data types in Java

Was this article helpful?

Related Articles

Leave A Comment?