Java data types

While we are on the subject of variables, let’s have a look at a taxonomy of data types. There are two main category of data types: primitives and objects. Primitives are the class of raw computer hardware data types supported by CPU’s, such as single and double precision floating point numbers. Computations using these types have the best possible performance. Objects are an encapsulation of code and local data. They supported safe modern programming practices and by their design they discourage chaotic programming patterns that are allowed in older procedural languages.

Primitive values are represented in programs using literal values. The following table lists examples of the literal values that are used for each primitive type:

TypeSample literal valuesData range



true or false
char‘a’Any Unicode character
byte(byte) 1-128 to 127
short(short) 2-32768 to 32767
int1234-231 to 231-1
long1224l (lower case L)-263 to 263-1

Smallest positive number that can be represented 2-149

Largest positive number that can be represented (2-2-23)·2127




Smallest positive number that can be represented 2-1074

Largest positive number that can be represented (2-2-52)·21023

The most commonly used primitives in the Patchworks API are booleans, doubles and integers. Chars, floats and longs are also used, but bytes and shorts are not required.

The same caveats that apply in other languages about floating point numbers also apply to BeanShell and Java: these numbers have a great range of value but are imprecise, so take care when performing comparisons.


For more information about the Java primitive data types search the web for “Java primitive data types”.