0% found this document useful (0 votes)
3 views3 pages

Kotlin Notes Part1 Detailed by ChatGPT

Kotlin is a modern, statically typed programming language that runs on the JVM and is primarily used for Android app development. It features simple syntax, null safety, and interoperability with Java, and includes variable types such as immutable (val) and mutable (var). The document also covers installation, data types, user input handling, and string manipulation in Kotlin.

Uploaded by

Ansh Choudhary
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)
3 views3 pages

Kotlin Notes Part1 Detailed by ChatGPT

Kotlin is a modern, statically typed programming language that runs on the JVM and is primarily used for Android app development. It features simple syntax, null safety, and interoperability with Java, and includes variable types such as immutable (val) and mutable (var). The document also covers installation, data types, user input handling, and string manipulation in Kotlin.

Uploaded by

Ansh Choudhary
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/ 3

Kotlin Notes by ChatGPT (Part 1)

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")
}

2. Kotlin Installation & Setup (IntelliJ IDEA)

1. IntelliJ IDEA ko install karo (official JetBrains IDE for Kotlin).


2. New Project create karo.
3. Language: Kotlin
4. Build System: Gradle (ya IntelliJ by default)
5. Project name do, location select karo.
6. 'src > main > kotlin' folder me .kt file banao aur code likho.

// File: Main.kt
fun main() {
println("Kotlin Installed Successfully")
}

3. Variables in Kotlin

Kotlin mein 2 types ke variables hote hain:


1. val (immutable) = value change nahi ho sakti
Kotlin Notes by ChatGPT (Part 1)

2. var (mutable) = value change ho sakti hai

Kotlin automatically datatype detect kar leta hai (type inference), par aap chaho to manually bhi de sakte ho.

val name = "Ansh" // Immutable


var age = 21 // Mutable

val city: String = "Delhi"


var marks: Int = 90

4. Data Types in Kotlin

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)

val isPassed: Boolean = true


val grade: Char = 'A'
val percentage: Float = 87.5f
val pi: Double = 3.14159
val rollNo: Int = 101
val studentName: String = "Ravi"

5. Input in Kotlin (Command Line)

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)

println("Enter your age:")


val age = readLine()!!.toInt()
println("You are $age years old")
}

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")

val name = "Ansh"


println("Length: ${name.length}")
println(name.uppercase())
println(name.lowercase())
println(name.substring(0,2))
println("Hello, $name")

You might also like