Data Types Flashcards

1
Q

Primitive Data Types

A

In Java, primitive data types are the most basic data types. There are 8 primitive data types in Java: boolean, byte, char, short, int, long, float, and double.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

int

A

Int, short for integer, is a data type that stores whole numbers (no decimals). The highest whole number that can be stored is 2,147,483,647. The lowest number that can be stored is -2147483648. If you try to store a number higher or lower than either of these, the computer will try to make sense of it, but can’t, resulting in an overflow or underflow and will present a completely different number than intended. An int occupies 32 bits of storage so we say it has a width of 32.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

byte

A

Byte, is a data type for storing whole numbers (no decimals). The highest whole number it can store is 127 and the lowest number it can store is -128. Byte was more common when Java first came out because smaller data types take up less room and can be processed quicker. However, with today’s memory and processing speed, Byte is used less and less. A byte occupies 8 bits of storage so we say it has a width of 8.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

short

A

Short, is a data type for storing whole numbers (no decimals). The highest whole number it can store is 32767 and the lowest whole number it can store is -32768. A short occupies 16 bits, so we say it has a width of 16.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

long

A

A long, is a data type for storing whole numbers (no decimals) larger than an int. It has a width of 64 bits, twice that of an int, and therefore can hold a number up to the size of 2 to the power of 63.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

float

A

Floating-point numbers, unlike whole numbers, have fractional parts, which we express with a decimal point. These are also known as real numbers. A float in Java has a width of 32 bits. Float is becoming outdated.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

double

A

Floating-point numbers, unlike whole numbers, have fractional parts, which we express with a decimal point. These are also known as real numbers. A double has a width of 64 bits in Java. Double is much more common than float and preferred. However, when precise calculations are required there is a Java-specific BigDecimal class that solves this problem and is preferred.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

char

A

The char data type in Java can store one single character as opposed to several characters as in the case of a string. A char, although a single character, occupies two bytes of memory, or 16 bits, so it has a width of 16.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

boolean

A

A boolean value allows for two choices, True or Fale, Yes or No, 1 or 0. In Java terms, we have a boolean primitive type and it can be set to two values only. true or false.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly