In addition to int, the Java programming language supports seven other primitive data types. A primitive type is predefined by the language and is named by a reserved keyword. Primitive values do not share state with other primitive values. The eight primitive data types supported by the Java programming language are:
Name | Description | Size | Range |
---|---|---|---|
Byte |
It is useful for saving memory in large arrays, where the memory savings actually matter. They can also be used in place of the int datatype where their limits help to clarify the code. The fact that a variable's range is limited can also serve as a form of documentation. |
8-bit | range |
Short |
It's used to save memory in large arrays, where memory savings actually matter |
16-bit | range |
Int |
It's used to save memory in large arrays, where memory savings actually matter |
32-bit | range |
Long |
This datatype is used when a range of values wider than those provided by int is needed. |
64-bit | range |
Float |
This is a single precision IEEE 754 floating point. Useful for saving a large array of floating point numbers, this shouldn't be used for precise values, such as currency. |
32-bit | range |
Double |
This is a double precision IEEE 754 floating point It's usually the default choice for decimal values and shouldn't be used for precise values, such as currency. |
64-bit | range |
Boolean |
This is a datatype that yields only two possible values: true and false. Use this data type for simple flags that track true/false conditions. The Boolean datatype represents one bit of information, but it's size isn't something that's precisely defined. |
size | range |
Char |
This datatype is a single unicode character. |
16-bit | range |
Symbol | Use |
---|---|
+ |
Additive or string concatenation |
- |
Subtraction |
/ |
Division |
% |
Remainder |
- |
Unary minus; negates an expression |
++ |
Increments value by 1 |
-- |
Decrements a value by 1 |
! |
Inverts the value of a boolean |
== |
Equal to |
!= |
Not equal to |
> |
Greater than |
>= |
Greater than or equal to |
< |
Less than |
<= |
Less than or equal to |
&& |
Conditional -AND |
|| |
Conditional -OR |
?: |
Ternary (short for if-then-else) |
~ |
Unary bitwise complement |
<< |
Signed left shift |
>> |
Signed right shirt |
>>> |
Unsigned right shift |
& |
Bitwise AND |
^ |
Bitwise exclusive OR |
| |
Bitwise inclusive OR |