Java Primitive Data Types

If you are looking for a new language to learn or learning a language for the first time, Java is not a bad choice. It has uses in many different developments and is popular everywhere. Java is a general-purpose programming language that is class-based and object-oriented. It is designed to use as few dependencies as possible and is intended to let us developers write once, run anywhere (WORA). This just means that the Java code is compiled once then can be run on all platforms that support Java without needing to be recompiled. Java’s syntax is similar to the C languages but has fewer low-level facilities. Java has seen significant use in 2019 particularly for client-server web applications.
Now that we have a little bit about Java let us go ahead and start looking at some actual Java. If you have learned any of the C languages then most of this will look extremely similar to you. Java has eight primitive data types, which I will cover today.
We are going to start with the Integer Types. The first of these is the byte. The byte can store whole numbers from -128 through 127. This is useful when you know the number will stay between the range of numbers to help save memory. The next type is a slight step up, it is short. This data type can store whole numbers from -32768 through 32767. The next type is where this group of data types defaults to, int. The int data type can store whole numbers from -2147483648 through 2147483647. The int data type is the preferred data type when we create variables with a numeric value. The final data type of the Integer Types is long. The long data type can store whole numbers from -9223372036854775808 through 9223372036854775807. Most commonly used when an int is not large enough to store the value. Do note that it is good practice to end the value with an “L”.

Perhaps it is easier to look at it in code compared to going through the paragraph above. At least it does look a lot easier to read as well as see how we can find the minimum and maximum values for each of these data types.
The next couple of primitive data types of Java fall into a new category, the Floating Point Types. When do you think we would use these types of data types? The name probably gives it away, but we use these whenever we need a number with a decimal. The first Floating Point Types is the float. This data type is a single-precision 32-bit IEEE 754 floating point. We mainly use this to save memory in large arrays of floating point numbers. It is good practice to add an “f” to the end of the value just like with the long data type. The other data type of the Floating Point Types is the double data type. It is a double-precision 64-bit IEEE 754 floating point. Like float, it is good practice to place a “d” at the end of the value. Neither of these data types should ever be used for precise values such as currency.

The final two Primitive Data Types are char and boolean. Each of these has its own uses but they are also highly specialized in what they can handle. The char data type can only accept a singular character such as “D”. Char is very useful in this way in that it can accept Unicode to create characters for us. The final data type the boolean is really only used to help us determine if something is true or false. It can only be one of two answers so it helps us out a lot when we want to compare something, such as is a person over the age of 21.
These are the primitive data types that are used in the Java programming language. If you have never looked at a language such as this I hope this overview has helped you see where you can use these data types. However, if you already knew a language such as one of the C’s hopefully this just helped you to either remember what each is or clarified where you can use each one of these specifically.
