What is a Long Data Type ?
In Java, the long data type denotes a 64-bit signed (two's-complement) integer, which can hold any value between -9,223,372,036,854,775,808 (-263) and 9,223,372,036,854,775,807 (263-1).
long is used whenever an int data type is not sufficient to represent a number.
The primitive typelong has a corresponding wrapper class called Long . Both long and Long can be used interchangeably. Which means, we can say:
22222222223L , 23L assigned to num1 and num2 respectively are called long literals.
As you can notice, the long literal values are suffixed with char 'L' (lowercase of 'L' can also be used, however the uppercase is more readable)
The default value of a primitivelong is 0L , when not initialized. However, the default value of a reference of type Long is null , when not initialized.
In Java 8 and later, long can also represent unsigned 64-bit integers, with a min value of 0 and a max value of 264-1.
To use unsigned long integers, use theLong class.
We will learn more about the wrapper classLong later.
Select all the correct statements given below.
The primitive type
long num1 = 22222222223L;
Long num2 = 23L;
Long total = num1 + num2;
long valueOfNum2 = total - num1;
The fixed values As you can notice, the long literal values are suffixed with char 'L' (lowercase of 'L' can also be used, however the uppercase is more readable)
The default value of a primitive
To use unsigned long integers, use the
We will learn more about the wrapper class
- The max value of a
long is twice the max value of anint - A
long can also represent decimal (fractional) numbers. - A
long literal value can be enclosed in single or double quotes. - A
long literal value can be a negative or a positive number within the range of -263 and 263-1.
0 Comments