The long Data Type - Java Language Basics

Java examples for Language Basics:long

Introduction

The long data type is a 64-bit signed Java primitive data type.

The long data type is used when the result of calculations may exceed the range of the int data type.

Its range is -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 (-2^63 to 2^63 - 1).

An integer literal of type long always ends with L (or lowercase l).

The following are examples of using a integer literal of long type:

  
long num1 = 0L; 
long num2 = 4000L; 
long mum3 = -3006L; 
long num4 = 80008L; 
long num5 = -1050L;  

Integer literals of long type can also be expressed in octal, hexadecimal, and binary formats.

For example,

long num1; 
num1 = 25L;       // Decimal format 
num1 = 0311L;     // Octal format 
num1 = 0X119L;    // Hexadecimal format 
num1 = 0b111001L; // Binary format 
  

Java class Long defines two constants to represent maximum and minimum values of long data type, Long.MAX_VALUE and Long.MIN_VALUE.

long max = Long.MAX_VALUE; 
long min = Long.MIN_VALUE;

Related Tutorials