Groovy - Data Types

In any programming language, you need to use various variables to store various types of information. Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory to store the value associated with the variable.
You may like to store information of various data types like string, character, wide character, integer, floating point, Boolean, etc. Based on the data type of a variable, the operating system allocates memory and decides what can be stored in the reserved memory.
Groovy offers a wide variety of built-in data types. Following is a list of data types which are defined in Groovy −
byte − This is used to represent a byte value. An example is 2.
byte − This is used to represent a byte value. An example is 2.
short − This is used to represent a short number. An example is 10.
short − This is used to represent a short number. An example is 10.
int − This is used to represent whole numbers. An example is 1234.
int − This is used to represent whole numbers. An example is 1234.
long − This is used to represent a long number. An example is 10000090.
long − This is used to represent a long number. An example is 10000090.
float − This is used to represent 32-bit floating point numbers. An example is 12.34.
float − This is used to represent 32-bit floating point numbers. An example is 12.34.
double − This is used to represent 64-bit floating point numbers which are longer decimal  number representations which may be required at times. An example is 12.3456565.
double − This is used to represent 64-bit floating point numbers which are longer decimal  number representations which may be required at times. An example is 12.3456565.
char − This defines a single character literal. An example is ‘a’.
char − This defines a single character literal. An example is ‘a’.
Boolean − This represents a Boolean value which can either be true or false.
Boolean − This represents a Boolean value which can either be true or false.
String − These are text literals which are represented in the form of chain of characters. For example “Hello World”.
String − These are text literals which are represented in the form of chain of characters. For example “Hello World”.
The following table shows the maximum allowed values for the numerical and decimal literals.
Types In addition to the primitive types, the following object types (sometimes referred to as wrapper types) are allowed −
java.lang.Byte
java.lang.Short
java.lang.Integer
java.lang.Long
java.lang.Float
java.lang.Double
In addition, the following classes can be used for supporting arbitrary precision arithmetic −
The following code example showcases how the different built-in data types can be used −
class Example { 
   static void main(String[] args) { 
      //Example of a int datatype 
      int x = 5; 
		
      //Example of a long datatype 
      long y = 100L; 
		
      //Example of a floating point datatype 
      float a = 10.56f; 
		
      //Example of a double datatype 
      double b = 10.5e40; 
		
      //Example of a BigInteger datatype 
      BigInteger bi = 30g; 
		
      //Example of a BigDecimal datatype 
      BigDecimal bd = 3.5g; 
		
      println(x); 
      println(y); 
      println(a); 
      println(b); 
      println(bi); 
      println(bd); 
   } 
}
When we run the above program, we will get the following result −