Primitives in Java Explained

Опубликовано: 01 Август 2022
на канале: Marvin Dale
61
3

There are 8 primitives in Java.
byte, short, int, long, float, double, boolean and char.
These are predefined types, named with a reserved keyword. These types aren't considered objects.
String is also a predefined type but it is not considered a primitive because it is a sub class of the Object class.
To declare a primitive you first type the data type you want, the name you want the variable to have, the equals sign, then the value you want to assign to the variable and then a semicolon.
Byte, short, int and long, are all versions of an integer type, integers being whole numbers, with byte taking up the least memory and long taking up the most.
If you need an integer value in your program without any specific memory requirements in mind usually you'll use an int.
Ints use 32 bits of memory, with a minimum value of 2E31 to 2E31 -1.
Short and byte are both smaller version of int.
Shorts take up 16 bits (-2E15 to 2E15 -1) of memory and bytes take up 8 bits (-2E7 to 2E7 -1) of memory.
These are usually used in situations where memory is limited or as a form of documentation within the code to improve clarity.
Long is the bigger version of int.
Longs take up 64 bits of memory (-2E63 to 2E63 -1)
When you want in integer literal to be of type long you need to add an upper or lower case L to the end of it.
Values of the types byte, short, int or long can all be created from Integer literals, which can be expressed in decimal, hexadecimal or binary number systems.


На этой странице сайта вы можете посмотреть видео онлайн Primitives in Java Explained длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Marvin Dale 01 Август 2022, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 61 раз и оно понравилось 3 зрителям. Приятного просмотра!