Types of primitive data

T

In Java, data types are divided into two categories: primitive types and reference types. Java starts from the premise as ” anything is an object ”, therefore data types should actually be defined by classes and all variables should store instances of these classes. Basically, this is true, but for ease of programming, there are also the so-called primitive types of data, which are the usual ones.
The Java programming language assumes that all variables are declared before they are used. This involves declaring the type and name of the variable.

int step = 1;

This tells the program that there is a field called the step that contains whole numbers and has an initial value 1. The data type of a variable determines the values ​​it can contain, as well as the operations that can be performed on them. In addition to int, the Java programming language supports seven other types of primitive data. A primitive type is predefined by the language and is named by a reserved keyword.

The eight types of primitive data supported by the Java programming language are:

1. byte
The byte data type is an integer with values ​​ranging from -128 to 127 (inclusive). The byte data type can be useful to save memory in large vectors where memory saving really matters. It can also be used instead of int, to indicate that the values ​​of a variable do not exceed the limits of this data type.

2. short
The short data type is an integer with values ​​between -32,768 and 32,767 (inclusive). As with the byte, you can use a short to save the memory in large strings, in cases where memory saving really matters.

3. int
The int data type is an integer in the range (-2.147.483.648, 2.147.483.647) For full values, this data type is the default choice unless there is a reason (as above) to choose This type of data will probably be large enough for the numbers your program will use, but if you need a wider range of values, use long.

4. long
The long data type is an integer between 9.223.372.036.854.775.808 and 9.223.372.036.854.775.807. Use this type of data if you need a wider range than the one provided by the int.

5. float
Float data type is 32-bit IEEE 754 floating point, simple 32-bit floating point numbers. Just like for byte and short recommendations, use float (instead of double) if you want to save memory in long strings of numbers floating point. This type of data should not be used for exact values, such as the exchange rate or the conversion rate between currencies. For these, use the java.math.BigDecimal class.

6. double
The double data type is a floating point representation, simple, 64-bit IEEE 754 precision. This type of data is the standard choice for rational values. As mentioned above, this data type should not be used for accurate values.

7. character: char (2 bytes)

8. logic: boolean (true and false)
In other programming languages, the format and size of primitive data types may depend on the platform on which the program runs. In Java this is no longer true, any addiction to a particular platform being eliminated.

Recent Posts

Archives

Categories