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 Comments & Variables (Lesson 3 PDF) 

Ahmed Elhozayen by Ahmed Elhozayen
October 11, 2026
in Kotlin
0
 Kotlin Comments & Variables (Lesson 3 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 Comments & Variables (Lesson 3 PDF) 

Overview about the Lesson

In this lesson, you will learn about comments and variables in Kotlin. You will learn how to use comments to document your code and make it more readable. You will also learn how to declare variables and constants in Kotlin.

 Kotlin Comments & Variables (Lesson 3 PDF)  – page 2
 Kotlin Comments & Variables (Lesson 3 PDF)  – page 3
 Kotlin Comments & Variables (Lesson 3 PDF)  – page 4
 Kotlin Comments & Variables (Lesson 3 PDF)  – page 5
 Kotlin Comments & Variables (Lesson 3 PDF)  – page 6

The Content of the Lesson

The lesson is divided into two parts. In the first part, you will learn about comments in Kotlin. You will learn how to use single-line and multi-line comments to document your code. You will also learn how to use comments to disable code temporarily. In the second part, you will learn how to declare variables and constants in Kotlin. You will learn about data types, type inference, and how to declare variables and constants.

Why This Lesson

This lesson is designed for programmers who are new to Kotlin and want to learn how to use comments and declare variables and constants. It is also suitable for programmers who are familiar with Java and want to learn Kotlin.

Kotlin Comments and Variables: val vs var Explained

This lesson’s PDF introduces comments and variables. Here are the key ideas with examples you can run in the Kotlin Playground.

Comments

// A single-line comment: ignored by the compiler

/*
   A multi-line comment
   for longer explanations
*/

/**
 * A KDoc comment documents functions and classes.
 * @param name the person to greet
 */
fun greet(name: String) = println("Hello, $name")

Good comments explain why code does something. Clear names usually explain what it does.

val and var

KeywordMeaningCan be reassigned?
valRead-only value (like a constant reference)No
varMutable variableYes
fun main() {
    val birthYear = 1998
    var score = 10
    score = score + 5      // OK: var can change
    // birthYear = 2000    // Error: val cannot be reassigned
    println("Born $birthYear, score $score")   // Born 1998, score 15
}

Rule of thumb: use val by default and switch to var only when the value really needs to change. Code with fewer changing values is easier to understand and has fewer bugs.

Type inference and explicit types

val city = "Cairo"           // Kotlin infers String
val count: Int = 5           // explicit type
var price: Double = 19.99
var nickname: String? = null // ? means the variable may hold null

Kotlin works out the type from the value, so you rarely need to write it. Add it when it makes the code clearer or when you declare a variable without a value yet.

Naming rules and conventions

  • Names can contain letters, digits and underscores, but cannot start with a digit.
  • Use camelCase for variables: totalPrice, userName.
  • Names are case-sensitive: total and Total are different.
  • Keywords such as val, fun or class cannot be used as names.
  • For true compile-time constants, use const val MAX_USERS = 100 at the top level, written in UPPER_SNAKE_CASE.

Common mistakes

  • Reassigning a val: the error “Val cannot be reassigned” means you should either use var or create a new value.
  • Changing the type: var x = 5 then x = "five" fails, because x is an Int.
  • Assigning null to a non-nullable type: add ? to the type if null is allowed.

Practice exercise

Create a read-only variable for a product name, a mutable variable for stock, reduce the stock by 2 and print the result.

fun main() {
    val product = "Keyboard"
    var stock = 10
    stock -= 2
    println("$product stock: $stock")   // Keyboard stock: 8
}

Frequently Asked Questions

Is val the same as final in Java?

Yes, a val behaves like a final variable: it can be assigned once. The object it points to can still be mutable (for example a MutableList).

When should I use const val?

For values known at compile time that never change, such as configuration limits or keys, declared at the top level or inside an object.

Continue the course

← Previous: Lesson 2: Syntax & Output  |  Next: Lesson 4: Data Types →

  1. Lesson 1: Getting Started
  2. Lesson 2: Syntax & Output
  3. Lesson 3: Comments & Variables (you are here)
  4. Lesson 4: Data Types
  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

Comments and variables are essential parts of any programming language. In this lesson, you learned how to use comments to document your code and make it more readable. You also learned how to declare variables and constants in Kotlin. 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: AndroidJavaJVMKotlinProgramming
Previous Post

Kotlin Syntax & Output (Print Text) (Lesson 2 PDF)

Next Post

Kotlin Data Type (Lesson 4 PDF)

Ahmed Elhozayen

Ahmed Elhozayen

Ahmed Elhozayen writes and curates the guides on Connect4Techs Tech. He works in the IT field and focuses on practical, step-by-step resources for Excel, data analysis, finance, MBA studies and Kotlin programming, so readers can apply what they learn the same day.

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 Data Type (Lesson 4 PDF)

Kotlin Data Type (Lesson 4 PDF)

Recommended

The MBA Application Process: A Comprehensive Guide PDF

The MBA Application Process: A Comprehensive Guide PDF

June 25, 2024
Finance Excel Guidelines- A Useful Guide for Accountants

Finance Excel Guidelines: A Useful Guide for Accountants

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
  • AI Tools & News (Connect4AI)
© 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