Groovy Supports all of the JAVA primitive and other complex data types and actually does some improvement on them.
Primitive = are types of data that can not be brake down into other data types.
So the Primitive types supported by Groovy are:
1 Numeric Primitives:
- Integers:
byte
– 8 bit (this means it occupies 8 bit of memory )
– values allowed are from -128 to +127
short
16 bit
– values allowed are from -32,768 to 32,767
int
32 bit
-values allowed are from -2,147,483,648 to 2,147,483,647
long
64 bit
-values allowed are from -9,223,372,036,854,775,808 to +9,223,372,036,854,775,807
- Floating Point
float
32 bit
the values allowed are so big that we need to use the scientific notation to express them 1.4e-045 to 3.4e+038
“A floating-point number is also known as a single-precision floating-point number. It can represent a real number as small as 1.4 x 10-45 and as big as 3.4 x 1038 in magnitude.” source
A floating-point number is also known as a single-precision floating-point number
this actually means that a primitive of type float takes only 1 decimal.
Example:
1.9 ;
3.0(even if a number has no decimals, a primitive float will put 0 after the decimal point)
double
64 bit
double is even bigger than float, values allowed are: 4.9e-324 to 1.8e+308
The double data type uses 64 bits to store a floating-point number. double value is also known as a double-precision floating-point number.
Example:
2.01;
3.00 (just like for the float type, even if no decimals, two 0 will be added in the decimal places)
2 Character Primitive:
char
16 bit
-can take values from 0 to 65535
-there are no negative char
-they are represented mostly by ASCII
3 Boolean
Boolean
-can have 2 values: true or false
-Boolean data type represents one bit of information
-default value is false
Class types
java.lang.Byte
java.lang.Short
java.lang.Integer
java.lang.Long
java.lang.Float
java.lang.Double
java.math.BigInteger
java.math.BigDecimal
java.lang.String
Now out of all of those class types most important in the context of Sales Cloud are java.lang.String and java.math.BigDecimal .
java.lang.String deals with texts, so values from Text Fields belong to this type
java.math.BigDecimal – this one is used in the numeric type fields.
Strings
You can think of strings as text.
Usually when we want to tell the code something is a string we encapsulate it in between double quotation marks ” “
However Groovy also permits using single quotation marks to signal string ‘ ‘
We will dedicate a post to talk about strings later on.
Big Decimals
This are float numbers with an arbitrary number of decimals
An example could be 3.987645554
This is useful because something we need more precision when expressing a number than what float and double primitive data types permit.
For example currency conversion rates, is not enough to use just 2 decimals to express them, we actually need more than that, here is where Big Decimals come in play.
As Big Decimals permit showing a larger number of decimals.
This is also the reason that all numeric fields in Engagement Cloud are actually Big Decimal Types