Basic Types and Literals
Numbers, booleans, and chars.
Basic Types and Literals is a free Scala for Backend Engineering & Functional Programming lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Scala for Backend Engineering & Functional Programming learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Scala's Basic Types
Scala ships with a small set of built-in value types you will use constantly.
Int,Longfor whole numbersDouble,Floatfor decimalsBoolean,Char,String
Each has a literal syntax for writing values directly in code.
Int Literals
A whole number with no decimal point is an Int by default, a 32-bit signed integer.
You can group digits with underscores for readability.
object Main extends App {
val year = 2026
val big = 1_000_000
println(year + big)
}Long Literals
When a number is too large for Int or you simply want 64 bits, add an L suffix to make it a Long.
The capital L is preferred over lowercase l for clarity.
val population: Long = 8_000_000_000L
val id = 42LDouble and Float Literals
A number with a decimal point is a Double by default. Add an f suffix for a Float.
You can also use scientific notation with e.
object Main extends App {
val price = 19.99
val rate = 0.5f
val mass = 6.02e23
println(price)
}Boolean Literals
A Boolean holds exactly one of two literals: true or false.
Booleans drive conditions, comparisons, and logical operators like && and ||.
object Main extends App {
val isReady = true
val isDone = false
println(isReady && !isDone)
}Char Literals
A Char is a single 16-bit Unicode character written in single quotes.
Do not confuse it with a one-letter String, which uses double quotes.
val grade = 'A'
val newline = '\n'
val letter: Char = 'z'String Literals
A String is text written in double quotes. You can join strings with +.
Escape sequences like \n and \t work inside ordinary strings.
object Main extends App {
val first = "Func"
val second = "tional"
println(first + second)
}String Interpolation
Prefix a string with s to embed expressions using $name or ${expr}.
This is cleaner than concatenating with + and is the idiomatic way to build text.
object Main extends App {
val user = "Sam"
val items = 3
println(s"$user has ${items * 2} items")
}Multiline Strings
Triple quotes """...""" create raw multiline strings where escapes are not processed.
They are great for JSON, SQL, or any block of text spanning several lines.
val sql = """SELECT *
FROM users
WHERE active = true"""The Unit Type
Unit is Scala's version of "no useful value", similar to void in Java.
Its single literal is (). Functions that exist only for side effects, like println, return Unit.
object Main extends App {
val nothing: Unit = ()
val result = println("side effect")
println(result)
}Types Form a Hierarchy
All these value types descend from AnyVal, which together with AnyRef sits under Any, the root of every Scala type.
At the bottom, Nothing is a subtype of everything. This unified hierarchy is why expressions always have a type.
Quick Check
Which literal matches which type?
Recap
You met Scala's core value types and their literals.
- Whole numbers:
Int,Long(withL). - Decimals:
Double,Float(withf). Boolean,Char(single quotes),String(double quotes).s"..."interpolation andUnitas the empty value.
Frequently asked questions
Is the “Basic Types and Literals” lesson free?
Yes — the full text of “Basic Types and Literals” is free to read here on the web, and the Scala for Backend Engineering & Functional Programming course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Scala for Backend Engineering & Functional Programming course, upgrade to CoddyKit PRO.
What will I learn in “Basic Types and Literals”?
Numbers, booleans, and chars. You practise Scala for Backend Engineering & Functional Programming with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Scala for Backend Engineering & Functional Programming?
No prior experience is required. Scala for Backend Engineering & Functional Programming on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Basic Types and Literals” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Scala for Backend Engineering & Functional Programming lesson?
Yes. Every Scala for Backend Engineering & Functional Programming lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- val vs var
- Basic Types and Literals
- Type Inference
- Expressions over Statements