![]() |
VOOZH | about |
A data type is a categorization of data which tells the compiler that which type of value a variable has. For example, if a variable has an int data type, then it holds numeric value. In Scala, the data types are similar to Java in terms of length and storage. In Scala, data types are treated same objects so the first letter of the data type is in capital letter. The data types that are available in Scala as shown in the below table:
| DataType | Default value | Description |
|---|---|---|
| Boolean | False | True or False |
| Byte | 0 | 8 bit signed value. Range:-128 to 127 |
| Short | 0 | 16 bit signed value. Range:-215 to 215-1 |
| Char | '\u000' | 16 bit unsigned unicode character. Range:0 to 216-1 |
| Int | 0 | 32 bit signed value. Range:-231 to 231-1 |
| Long | 0L | 64 bit signed value. Range:-263 to 263-1 |
| Float | 0.0F | 32 bit IEEE 754 single-Precision float |
| Double | 0.0D | 64 bit IEEE 754 double-Precision float |
| String | null | A sequence of character |
| Unit | - | Coinsides to no value. |
| Nothing | - | It is a subtype of every other type and it contains no value. |
| Any | - | It is a supertype of all other types |
| AnyVal | - | It serve as value types. |
| AnyRef | - | It serves as reference types. |
Note: Scala does not contain the concept of primitive type like in Java. For Example:
Output:
boolean:geeksforgeeks byte:126 float:2.45673 integer:3 short:45 double:2.93846523 char:A
Literals in Scala : Here we will discuss different types of literals used in Scala.
02 0 40 213 0xFFFFFFFF 0743L
0.7 1e60f 3.12154f 1.0e100 .3
package scala final case class Symbol private (name: String) { override def toString: String = "'" + name }
'\b' 'a' '\r' '\u0027'
"welcome to \n geeksforgeeks" "\\This is the tutorial of Scala\\"
"""welcome to geeksforgeeks\n this is the tutorial of \n scala programming language"""