In the Java programming language, you can use variables with type byte, int, long to store integers. An integer is actually a complete number that does not have a decimal point. The int data type is used most often for the use of integers. An int variable can be an integer between 2,147,483,648 and 2,147,483,647+. When you assign a value to a variable of type int, you should not use that comma and dot in that amount. Only use digits and a positive or negative sign (which is optional).
Legal values are numbers, integer, from 2 31 – to 1-2 31 are. These numbers represent the smallest and the highest values that you can store in 4 bytes of memory. Which represents the size of an int variable.
Byte and short and long types also specify different types of integer data (integers). Byte and short types occupy less memory and can hold smaller values. The long data type takes up more memory and can hold up larger values. In Table 2.2, for each of these data types, we have defined the lowest and highest values:
In other programming languages, the format and size of a primary data type may depend on the operating system on which the program is running. But the Java language always determines the format and size of the primary data type.
It’s important to choose the right data type for your program variables. If you try to assign a greater value than the data type of a variable, the compiler will create an error and your program will not run. And if you use a data type that is larger than you need, you have wiped out the memory.
If an application uses an integer value, such as 932, it will default to the int. If you need to use a constant greater than 2,147,483,647, you should look for this number of letters L to specify the length type for it. For example, in the following statement, a number greater than the maximum value of the int type is stored in one variable:
long mosquitosInTheNorthWoods = 2444555888L;
To specify the long data type, you can also use both small letters L and large L. But to avoid similarity with number 1, it is better to use the big letter L. There is no need to use a special mark to store a numerical value byte or short. Because the correct integers such as 18 are of the int type by default, almost always in the book, when the task of an integer variable is correct, we use the int type data. Even if the value you want to save in a variable is less than 127, we’ll still use the int type data. But if you are writing an application that is important for your memory usage, you can use the byte data type for your variable