What are the primitive data types?

Primitive data types are a predefined way of storing data inside a program. They are the basic units of the program and the building blocks for derived data types. Primitive data types are distinct from non-primitive ones in several ways, which I will detail in the following paragraphs. At the end of the article, I will also bring up a comprehensive list of primitive data types in Java.

First of all, how primitive data are stored in the memory is defined and implemented by the compiler. The compilers dictate the number of bits and how the bits are ordered to represent primitive data. The compilers handle the details so perfectly that normal programmers do not have to get their hands dirty manipulating bits. In fact, some primitive data types are so commonly used that ISO even stands out to standardize the ways how computers handle them. For example, every textbook in computer science illustrates how a number is stored in memory. A small integer can be represented with one byte while a large integer has to occupy 8 bytes. In addition, the first bit of a number can denote its sign.

Secondly, literals are usually available for primitive data types. The compilers usually design a concise syntax for programmers to declare primitive data because of their frequent use in the program. It is unacceptable that programmers have to write tens of lines of code just to create an integer. Furthermore, the syntax of the literal is often designed in a way that mimics how we use them in daily life. In fact, the variation in the syntax of the literals between programming languages is unsurprisingly minimal. For example, to create an integer in the program, you simply put the digits in your code the same way you do on the blackboard. The readers of the code would also be familiar and comfortable with such representation.

Having spoken enough about what makes primitive data types special, I want to talk about the ones defined in Java by referring to the official tutorial available here. There are eight primitive data types in total, which can be put into two categories - the logical type, and the numerical type. The only logical type is boolean. All the others are numerical and can be further divided into two categories - the integral type, and the floating-point type. The integral category comprises byte, short, int, long, and char. The char type is also used to represent characters. Lastly, float and double fall into the floating-point category.