# Datatypes & Operators

## Primitive datatypes

The names of each of the following primitive datatypes are all keywords:

• byte: 8-bit signed integer ranging from -128 to 127 inclusive; default: 0
• short: 16-bit integer ranging from -32 768 to 32 767 inclusive; default: 0
• int: 32-bit integer ranging from -2 147 483 648 to 2 147 483 647 inclusive; default: 0
• long: 64-bit integer ranging from -9 223 372 036 854 775 808 to 9 223 372 036 854 775 807 inclusive; default: 0L
• float: single-precision 32-bit floating point values following the IEEE 754 standard; default 0.0f
• double: double-precision 64-bit floating point values following the IEEE 754 standard; default 0.0d
• boolean: the logical values `true` and `false`; default: `false`
• char: a single 16-bit Unicode character ranging from `'\u0000'` to `'\uFFFF'`; default `'\u0000'` (NUL); see also Unicode character table

You might like to read these sections of the variables tutorial:

1. Primitive Data Types
2. Arrays
3. Summary of Variables

and attempt the Questions and Exercises.

## Operators

Read these sections of the Operators tutorial:

1. Assignment, Arithmetic, and Unary Operators
2. Equality, Relational, and Conditional Operators
3. omit Bitwise and Bit Shift Operators
4. Summary of Operators

and attempt the Questions and Exercises.

## Floating-point comparisons

This section is drawn from Horstmann, 2002, pp. 192–193.

Since floating-point numbers have limited precision, it’s common practice to determine the equivalence of two such numbers by comparing their difference to a very small value called ε (lowercase epsilon), as in this sample program. However, the question arises: how small should ε be?

A common answer is 10-14, which could be rendered in code as `final double EPSILON = 1E-14`. But for very large numbers, a non-significant difference could easily be larger than 10-14.

To solve such problems, we should calculate the difference of the two numbers, determine what portion of the larger number this difference is, and compare that proportion to ε. Here’s one such implementation:

`Math.abs(x - y) / Math.max(Math.abs(x), Math.abs(y)) <= EPSILON;`

Of course, this implementation requires that both x and y are non-zero. If one of them is zero, all we can do is test whether the absolute value of the other is larger than ε:

`// If x is non-zero:Math.abs(x) <= EPSILON;// otherwise:Math.abs(y) <= EPSILON;`