Cloud Computing - SCALA

Back to Course

Lesson Description

Lession - #659 SCALA Data Types

SCALA datatypes

An data type is an arrangement of data which lets the compiler know what kind of significant worth a variable has. For instance, in the event that a variable has an int data type, it holds numeric value. In Scala, the data types are like Java regarding length and capacity. In Scala, data types are dealt with same items so the main letter of the data type is in capital letter. The data types that are accessible in Scala as displayed in the following table:

1 .Byte
8 bit signed value. Range from -128 to 127

2 .Short
16 bit signed value. Range -32768 to 32767

3 .Int
32 bit signed value. Range -2147483648 to 2147483647

4 .Long
64 bit signed value. -9223372036854775808 to 9223372036854775807

5 .Float
32 bit IEEE 754 single-precision float

6 .Double
64 bit IEEE 754 double-precision float

7 .Char
16 bit unsigned Unicode character. Range from U+0000 to U+FFFF

8 .String
A sequence of Chars

9 .Boolean
Either the literal true or the literal false

10 .Unit
Corresponds to no value

11 .Null
null or empty reference

12 .Nothing
The subtype of every other type; includes no values

13 .Any
The supertype of any type; any object is of type Any

14 .AnyRef
The supertype of any reference type

For Example:

// Scala program to illustrate Datatypes
object Test
def main(args: Array[String]>
{ var a: Boolean = true var a1: Byte = 126 var a2: Float = 2.45673f var a3: Int = 3 var a4: Short = 45 var a5: Double = 2.93846523 var a6: Char = 'A' if (a == true>
{ println("boolean:geeksforgeeks">
} println("byte:" + a1>
println("float:" + a2>
println("integer:" + a3>
println("short:" + a4>
println("double:" + a5>
println("char:" + a6>
} }