Connect 4 Techs
  • Home
  • Excel
  • Data Analysis
  • Finance
  • MBA
    • Marketing
  • Kotlin
  • Gadgets
    • Apple
    • Samsung
    • Canon
    • Tech News
  • About
  • Contact
No Result
View All Result
Connect 4 Techs
  • Home
  • Excel
  • Data Analysis
  • Finance
  • MBA
    • Marketing
  • Kotlin
  • Gadgets
    • Apple
    • Samsung
    • Canon
    • Tech News
  • About
  • Contact
No Result
View All Result
Connect 4 Techs
No Result
View All Result
Home Kotlin

Kotlin Data Type (Lesson 4 PDF)

Ahmed Elhozayen by Ahmed Elhozayen
October 11, 2026
in Kotlin
0
Kotlin Data Type (Lesson 4 PDF)

Kotlin is a statically typed programming language that runs on the Java Virtual Machine (JVM). It was developed by JetBrains and is now an official language for Android development. Kotlin is designed to be concise, expressive, and safe. It is also interoperable with Java, which means that you can use Kotlin and Java code together in the same project.

Kotlin

You might also like

Kotlin Class Functions & Inheritance (Lesson 13 PDF)

Kotlin Classes and Objects & Constructors (Lesson 12 PDF)

Kotlin Functions & Classes (Lesson 11 PDF)

Kotlin Data Type (Lesson 4 PDF)

Overview about the Lesson

In this lesson, you will learn about data types in Kotlin. You will learn about the basic data types such as numbers, characters, and booleans. You will also learn about arrays, strings, and nullability.

The Content of the Lesson

The lesson is divided into two parts. In the first part, you will learn about the basic data types in Kotlin. You will learn about numbers, characters, and booleans. You will also learn about type inference and how to declare variables and constants.

In the second part, you will learn about arrays, strings, and nullability. You will learn how to declare arrays, how to work with strings, and how to handle null values.

Why This Lesson

This lesson is designed for programmers who are new to Kotlin and want to learn about data types. It is also suitable for programmers who are familiar with Java and want to learn Kotlin.

Kotlin Data Types at a Glance

The PDF explains each data type in detail. This reference summarises them with examples and shows the conversions beginners get stuck on.

Number types

TypeSizeRange / precisionExample
Byte8 bits−128 to 127val b: Byte = 100
Short16 bits−32,768 to 32,767val s: Short = 2000
Int32 bitsabout ±2.1 billionval i = 42
Long64 bitsabout ±9.2 × 1018val l = 42L
Float32 bitsabout 6–7 significant digitsval f = 3.14f
Double64 bitsabout 15–16 significant digitsval d = 3.14

Whole numbers default to Int (or Long if too big for Int); decimals default to Double. Use underscores for readability: val population = 106_000_000.

Other basic types

fun main() {
    val isActive: Boolean = true
    val grade: Char = 'A'           // single quotes for Char
    val message: String = "Hello"   // double quotes for String
    println("$isActive $grade ${message.length}")   // true A 5
}

Type conversion

Kotlin never converts number types silently, which prevents subtle bugs. Convert explicitly:

fun main() {
    val count: Int = 7
    val total: Long = count.toLong()
    val ratio: Double = count.toDouble() / 2   // 3.5
    val text = "123"
    val number = text.toInt()                  // 123
    val safe = "12a".toIntOrNull()             // null instead of a crash
    println("$total $ratio $number $safe")     // 7 3.5 123 null
}

Use toIntOrNull() whenever the text comes from a user or a file, because toInt() throws an exception on invalid input.

Nullable types

var email: String? = null      // may be null
println(email?.length)         // safe call: prints null
println(email ?: "no email")   // Elvis operator: fallback value

A type without ? can never hold null. This is one of Kotlin’s most important safety features.

Checking a value’s type

fun describe(x: Any): String =
    if (x is String) "Text of length ${x.length}" else "Not text"

After x is String, Kotlin automatically treats x as a String inside that branch (a smart cast).

Practice exercise

Read the string “45” as a number, add 5 and print the result as a Double.

fun main() {
    val input = "45"
    val result = (input.toInt() + 5).toDouble()
    println(result)   // 50.0
}

Frequently Asked Questions

Does Kotlin have primitive types like Java?

Everything looks like an object in Kotlin code, but the compiler uses JVM primitives (int, double…) under the hood whenever it can, so there is no performance penalty.

Why does 0.1 + 0.2 not print exactly 0.3?

Double stores numbers in binary, so some decimals cannot be represented exactly. For money, use BigDecimal or work in whole cents with Long.

Continue the course

← Previous: Lesson 3: Comments & Variables  |  Next: Lesson 5: Operators →

  1. Lesson 1: Getting Started
  2. Lesson 2: Syntax & Output
  3. Lesson 3: Comments & Variables
  4. Lesson 4: Data Types (you are here)
  5. Lesson 5: Operators
  6. Lesson 6: Set Operations & Grouping
  7. Lesson 7: Booleans & If…Else
  8. Lesson 8: When, While, Break & Continue
  9. Lesson 9: Arrays
  10. Lesson 10: For Loops & Ranges
  11. Lesson 11: Functions & Classes
  12. Lesson 12: Classes, Objects & Constructors
  13. Lesson 13: Class Functions & Inheritance

Conclusion

Data types are an essential part of any programming language. In this lesson, you learned about the basic data types in Kotlin such as numbers, characters, and booleans. You also learned about arrays, strings, and nullability. With these skills, you can write more efficient and maintainable code.

Download From Link

You can download the lesson from the following link:

From Here:

Tags: AndroidJavaJVMKotlinProgrammingtechnology
Previous Post

 Kotlin Comments & Variables (Lesson 3 PDF) 

Next Post

Kotlin Operators (Lesson 5 PDF)

Ahmed Elhozayen

Ahmed Elhozayen

Related Posts

Kotlin Class Functions & Inheritance (Lesson 13 PDF)
Kotlin

Kotlin Class Functions & Inheritance (Lesson 13 PDF)

by Ahmed Elhozayen
October 11, 2026
Kotlin Classes and Objects & Constructors (Lesson 12 PDF)
Kotlin

Kotlin Classes and Objects & Constructors (Lesson 12 PDF)

by Ahmed Elhozayen
October 11, 2026
Kotlin Functions & Classes (Lesson 11 PDF)
Kotlin

Kotlin Functions & Classes (Lesson 11 PDF)

by Ahmed Elhozayen
October 11, 2026
Kotlin For Loop & Kotlin Ranges (Lesson 10 PDF)
Kotlin

Kotlin For Loop & Kotlin Ranges (Lesson 10 PDF)

by Ahmed Elhozayen
October 11, 2026
 Kotlin Arrays (Lesson 9 PDF)
Kotlin

 Kotlin Arrays (Lesson 9 PDF)

by Ahmed Elhozayen
October 11, 2026
Next Post
Kotlin Operators (Lesson 5 PDF)

Kotlin Operators (Lesson 5 PDF)

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recommended

Post MBA Transition: Navigating the Path to Success PDF

Post MBA Transition: Navigating the Path to Success PDF

June 26, 2024
Which Chart When?

Types of Chart and Which One When? PDF

October 11, 2026

Categories

  • apple
  • Canon
  • Data Analysis
  • Excel
  • Finance
  • ios
  • Kotlin
  • Marketing
  • MBA
  • Samsung
  • Software Tutorials
  • Technology

Don't miss it

20 Essential Excel Formulas Every Data Analyst Must Know in 2026
Data Analysis

20 Essential Excel Formulas Every Data Analyst Must Know in 2026

May 18, 2026
Excel guide for data analytics learners
Excel

Excel for Data Analysis PDF

October 11, 2026
The Ultimate Guide to Financial Modeling PDF
Excel

The Ultimate Guide to Financial Modeling PDF

October 11, 2026
The Ultimate Excel Handbook PDF
Excel

The Ultimate Excel Handbook PDF

October 11, 2026
𝟓𝟎 𝐄𝐱𝐜𝐞𝐥 𝐒𝐡𝐨𝐫𝐭𝐜𝐮𝐭 𝐊𝐞𝐲
Excel

50 Excel Shortcut Key PDF: Streamline Your Workflow

March 21, 2025
Most Useful Excel Keyboard Shortcuts For Windows and Mac OS
Excel

Most Useful Excel Keyboard Shortcuts for Windows and Mac OS PDF

March 21, 2025
Connect4Techs Tech

Practical, free guides on Excel, data analysis, finance, business and programming — written to help you learn faster and work smarter.

Follow on Facebook

Topics

  • Excel
  • Kotlin
  • MBA
  • Finance
  • Data Analysis
  • Apple
  • Technology
  • Software Tutorials

Latest articles

  • 20 Essential Excel Formulas Every Data Analyst Must Know in 2026May 18, 2026
  • Excel for Data Analysis PDFAug 31, 2025
  • The Ultimate Guide to Financial Modeling PDFApr 19, 2025

Company

  • About us
  • Contact
  • Privacy Policy
  • Terms of Use
  • IT Certification PDFs
© 2026 Connect4Techs. All rights reserved. Privacy · Terms · Contact
No Result
View All Result
  • Home
  • Excel
  • Data Analysis
  • Finance
  • MBA
    • Marketing
  • Kotlin
  • Gadgets
    • Apple
    • Samsung
    • Canon
    • Tech News
  • About
  • Contact