0% found this document useful (0 votes)
167 views7 pages

Kotlin Beginners Guide

Kotlin is a modern programming language developed by JetBrains, designed to run on the Java Virtual Machine and widely used for Android development. The document covers essential features of Kotlin, including its syntax, data types, control structures, functions, and null safety, along with practical examples in both Urdu and English. It also provides tips for learning Kotlin effectively and suggests resources for further practice.

Uploaded by

humayunakbar841
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
167 views7 pages

Kotlin Beginners Guide

Kotlin is a modern programming language developed by JetBrains, designed to run on the Java Virtual Machine and widely used for Android development. The document covers essential features of Kotlin, including its syntax, data types, control structures, functions, and null safety, along with practical examples in both Urdu and English. It also provides tips for learning Kotlin effectively and suggests resources for further practice.

Uploaded by

humayunakbar841
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

📘 Kotlin Programming Language - Complete

Beginner's Guide (Urdu + English)

🧑💻 Kotlin Kya Hai?


Kotlin aik modern aur powerful programming language hai jo JetBrains ne banayi hai. Ye Java Virtual
Machine (JVM) par chalta hai aur Android development mein Java ka replacement ban chuka hai.

✨ Features:

• Concise (kam code likhna padta hai)


• Null Safety (null error ka khatra kam)
• Functional + Object-Oriented (dono styles ka support)
• Java ke sath fully compatible (Java aur Kotlin dono mil ke kaam kar sakte hain)

🔹 1. Hello World Example

fun main() {
println("Hello, Kotlin!")
}

Note: main() har Kotlin program ka starting point hota hai.

Roman Urdu Explanation: Yeh program sirf "Hello, Kotlin!" ko screen par print karega. println() ka
matlab hai line mein print karo.

🔹 2. Variables (Mutaghayyirat)

➤ Immutable (Jo change nahi hoti): val

val country = "Pakistan"

Yeh value fix hai, change nahi ki ja sakti.

1
➤ Mutable (Jo change ho sakti hai): var

var age = 20
age = 21

var se value ko baad mein change kar sakte hain.

Roman Urdu Explanation: val aik fix value hoti hai, jab ke var ko baad mein update kiya ja sakta hai.

🔹 3. Data Types

Type Example Description

Int val num = 5 Integer value

Double val pi = 3.14 Decimal value

String val name = "Ali" Text value

Boolean val isActive = true true / false value

Char val grade = 'A' Single character

Roman Urdu Explanation: Har variable ka aik type hota hai, jaise Int numbers ke liye, String text ke
liye, Boolean true ya false ke liye.

🔹 4. String Templates

val name = "Sanober"


val message = "Hello, my name is $name"
println(message)

Roman Urdu Explanation: $name variable ko string ke andar use karte hain taake dynamic message ban
sake.

🔹 5. Input from User

fun main() {
print("Enter your name: ")
val name = readLine()

2
println("Welcome, $name!")
}

Roman Urdu Explanation: readLine() user se input leta hai aur usay variable mein save karta hai.

🔹 6. Conditional Statements

➤ If-Else

val age = 18
if (age >= 18) {
println("Adult")
} else {
println("Minor")
}

Age check karne ke liye if-else use hota hai.

➤ When Expression (like switch)

val day = 2
when (day) {
1 -> println("Monday")
2 -> println("Tuesday")
else -> println("Unknown")
}

Roman Urdu Explanation: if-else aur when dono conditional logic ke liye use hote hain, jaise choices
banana.

🔹 7. Loops

➤ For Loop

for (i in 1..5) {
println("Number: $i")
}

3
➤ While Loop

var i = 1
while (i <= 5) {
println(i)
i++
}

Roman Urdu Explanation: Loops repeat karne ke liye use hote hain — for loop range ke sath aur
while tab tak jab tak condition true ho.

🔹 8. Functions

➤ Function Without Parameters

fun greet() {
println("Hello, welcome!")
}

➤ Function With Parameters and Return

fun add(a: Int, b: Int): Int {


return a + b
}

val result = add(3, 5)


println("Sum: $result")

Roman Urdu Explanation: Function aik block hota hai jo kuch kaam karta hai. Parameters input hotay hain
aur return output deta hai.

🔹 9. Arrays & Lists

➤ Arrays

val numbers = arrayOf(1, 2, 3, 4)


println(numbers[2]) // 3

4
➤ Lists

val items = listOf("Apple", "Banana")


println(items[1])

➤ Mutable List

val fruits = mutableListOf("Apple")


fruits.add("Mango")

Roman Urdu Explanation: Array ya list aik group hota hai values ka. Indexing 0 se start hoti hai.

🔹 10. Classes and Objects

class Person(val name: String, var age: Int) {


fun sayHello() {
println("Hello, my name is $name")
}
}

val p1 = Person("Ayesha", 22)


p1.sayHello()

Roman Urdu Explanation: Class aik template hoti hai object banane ke liye. Object class ka instance hota
hai.

🔹 11. Null Safety (Bohat Important)

var name: String? = null


println(name?.length) // Safe call

val length = name?.length ?: 0 // Elvis operator

Roman Urdu Explanation: Kotlin mein null value ko handle karna easy hai taake app crash na ho.

5
🔹 12. Exception Handling

try {
val x = 5 / 0
} catch (e: ArithmeticException) {
println("Cannot divide by zero")
} finally {
println("Done")
}

Roman Urdu Explanation: Agar koi error aaye to usay try-catch block mein handle karte hain.

🔹 13. Kotlin in Android (Basic Example)

button.setOnClickListener {
textView.text = "Button Clicked!"
}

Roman Urdu Explanation: Yeh Android code hai jahan button click hone par textView change hota hai.

🔹 14. Kotlin Extensions

fun String.firstChar(): Char {


return this[0]
}

val myChar = "Kotlin".firstChar()


println(myChar)

Roman Urdu Explanation: Extensions se existing types mein new function add kar sakte hain bina unhe
change kiye.

🏁 Final Tips for Learning Kotlin


• Rozana chhoti apps ya snippets banao.
• Android Studio install karo aur "Kotlin Playground" practice karo.
• JetBrains ke official Kotlin Docs par visit karo.
• YouTube par "Kotlin for Beginners" series dekho (Apna pace rakho).

6
Agar aap chahen toh mein is content ko interactive course, PDF, ya Android project ke format mein bhi tayar
kar sakta hoon. Batayein agla step kya hona chahiye?

You might also like