Kotlin Notes Part1 Detailed by ChatGPT
Kotlin Notes Part1 Detailed by ChatGPT
1. Kotlin Introduction
Kotlin ek statically typed, modern programming language hai jo JVM (Java Virtual Machine) par run karti hai.
Yeh concise (short likhne layak), safe (null safety), interoperable (Java ke sath kaam kar sakti hai), aur
tool-friendly hoti hai.
Kotlin ka use mostly Android App Development mein hota hai. 2017 mein Google ne ise Android ke liye
official language banaya.
Features:
- Simple syntax
- Null safety
- Functional programming support
- Java ke sath easily use ho sakti hai (Interoperability)
- Open source hai
fun main() {
println("Hello, Kotlin")
}
// File: Main.kt
fun main() {
println("Kotlin Installed Successfully")
}
3. Variables in Kotlin
Kotlin automatically datatype detect kar leta hai (type inference), par aap chaho to manually bhi de sakte ho.
Primitive types:
- Int: poore number (e.g. 1, 99)
- Double: decimal (e.g. 3.14)
- Float: decimal with less precision
- Boolean: true/false
- Char: single character (e.g. 'A')
- String: text
Kotlin mein sab kuch Object hai (primitive bhi wrappers ke form me)
User se input lene ke liye Kotlin mein 'readLine()' function use hota hai.
Agar number lena ho to usko proper datatype mein convert karna padta hai using toInt(), toFloat(), etc.
fun main() {
println("Enter your name:")
val name = readLine()
println("Welcome, $name")
Kotlin Notes by ChatGPT (Part 1)
6. String Handling
String ek immutable datatype hai. Aap usme indexing, length check, concatenation, uppercase/lowercase,
interpolation sab kar sakte ho.
Useful functions:
- .length
- .uppercase(), .lowercase()
- .substring()
- string templates ("My name is $name")