The long keyword

long is a keyword in java that is used to store 64-bit integer (Java primitive type) value.

The long keyword

The long keyword

     

long is a keyword in java that is used to store 64-bit integer (Java primitive type) value. Keywords are basically reserved words which have specific meaning relevant to a compiler. The keyword long in java is also used to declare an expression, method return value, or variable of type long integer. The Long class in java programming language wraps a long type primitive value in an object. An Long type object includes only a single field whose type is long. Wrapper class is used to convert the long primitive values into Long type objects. In addition to this Long wrapper class also provides methods for converting a long to String and vice versa as well as other constants and methods that are useful to deal with long type.

Syntex:  Here is the syntax that displays how to declare and define a long type variable.

long number = 5;

Here are some more examples.

long anotherNumber = 34590L;

long octalNumber = 0377;

long hexNumber = 0xffl;

Note: Here are some points that must consider in case of long data type.

  • The Long class in java programming language is a wrapper class in order to support the long primitive type. Constants MIN_VALUE and MAX_VALUE are used to represent the range of values for this type.

  • In java programming language all integer literals are 32−bit int values unless the value is followed by l or L as in 235L, which specifies that the value should be interpreted as a long.