What does that mean in Java 16

Java data types

In this article, we'll tell you which primitive data types it in Java there and which properties they own. You will also find a at the end of the article Table, in which all Java data types with their associated Range of values are presented in a clear form.

You want that eight primitive data types of Java understand quickly? Then be sure to check out ours Video to do this!

Java data types - what is a data type?

Basically there is eight primitive data types, all other data types will be Objects called. An object is a larger block of data made up of many internal parts and in which Classes be included. For now, let's just look at those eight primitive data types.

But what is one anyway Java data type? Around Java data types To understand, you need to know that a computer memory can have any number Bit pattern contains. Bit pattern represent the information that a computer carries with the help of various Combinations the Numbers zero and one represent. a Data type is a scheme for using bits to represent values. These values ​​do not have to consist of numbers, but can contain any type of data that a computer can process.

Primitive data types Java

The eight primitive data types have the following names:,, (integer),,,, (character) and. Each of these types has a fixed number of bits. In addition, they can be divided into groups. Numbers are so important in Java that six of the eight are Java data types numeric are. This means that each of these, except for this and that, Numerical values stores.

Numeric Java data types can be in integer types and Floating point types subdivide. ,, and thus form the integer types and and that Floating point types.

Now one can ask why it is for numerical values several Java data types gives. In efficient programming, how much is crucial Storage the program takes.

Java long and Java byte

That means if you, for example, a numeric data type a small number want to assign, then it would be pure Waste of memory for that Data type to use. Because the data type has a size of 64 bit! That means he can whole numbers In the range of -263 to 263-1 represent.

So why should you use such a large data type if for a small number, for example 112, which type would be perfectly sufficient? It has a size of 8 bit and owns one Range of values of -128 to +127. Therefore it is important to know which type you should use in order to save as much memory as possible.

With small programs it hardly makes a difference. However, should you ever work on a larger project, it is very important how you handle these data types. The most common integer primitive data type is the one since he is a reasonable one Range of values With 32 bit owns.

The primitive data types have different tasks. So you can, for example if you are a Data type a Point number want to assign none or use.

Java double and Java float

This task is handled by the Type and taken, being in programs Floating point literals one Decimal point and no commas to have. Since both have the same task, it is of course clear that both are of different sizes.

Thus is with 64 bit twice as big as with 32 bit and therefore has a much larger range of values. So is often called a Floating point type With "Single accuracy" referred to while Floating point type With "Double precision" is called. In Java it is common to almost always use the floating point type for decimal numbers and only in special circumstances, for example if you are working with a file with 32 bit float data want to process. If you try to mix these floating point types, data can be lost.

If you explicitly have a Float literal, So if you want to request a character string that represents a float value, you have to write a capital or small "f" at the end of the decimal point. The same goes for a too Double literal, by putting a capital or small "d" at the end.

Java char and Java boolean

There are only two left Java data types left. On the one hand the Java data type, which one Character data stores and the Java data type. In most programming languages, the data type only uses 8 bit, in Java will however 16 bit used so that characters from other languages ​​can also be displayed as characters from English. A variable can only a single character represent. Around multiple characters You have to be able to store them in a row Objects which are constructed from char data. An example would be Strings, which consist of one or more char data. Character literals of Java data type are always from one single quotation mark locked in. Characters or strings ending with double quotes are included Strings and not a primitive data type.

The last primitive data type is the . This Java data type is, probably the easiest of them all, and its job is to input or output. You heard right, a Boolean value can only have one of two values: or. This value can be stored in a simple one and used for various expressions. For example, if you have a method in a program that checks whether the sun is shining or not. If the sun is actually shining, then the Boolean value of this method would be, otherwise it would be.

Java data types table

You can find them all in the table below Java data types with your associated value range clearly listed:

Java data typesizeRange of values
boolean8 bittrue / false
byte8 bit-27 up to 27-1
short16 bit-215 up to 215-1
char16 bit0 to 65535
int32 bit-231 up to 231-1
float32 bit+/- 1.4E-45 to +/- 3.4E + 38
long64 bit-263 up to 263-1
double64 bit+/- 4.9E-324 to +/- 1.7E + 308

Java data types application

You need the different data types for the Java methods, for example. We explain exactly how this works in our video!