← Back to Kotlin Course | Chapter 1: Setup & Basics | Lesson 1 of 7

Kotlin परिचय

Kotlin एक friendly programming language है जो आपको computer को साफ़, step-by-step instructions देने देती है, और यह Android phones पर भी चलती है।

What is Kotlin?

Kotlin एक general-purpose, statically-typed programming language है जिसे JetBrains ने Java के एक ज़्यादा संक्षिप्त और सुरक्षित विकल्प के रूप में बनाया।

यह Java Virtual Machine (JVM) पर चलती है, इसलिए यह किसी भी मौजूदा Java library का उपयोग कर सकती है, लेकिन यह null safety, data classes, और extension functions जैसी modern features जोड़ती है।

Note: Kotlin आज़माने के लिए आपको Android Studio की ज़रूरत नहीं -- standalone kotlinc compiler किसी भी terminal से plain .kt files चला सकता है।

उदाहरण: What is Kotlin?

markup
// Entry point: execution of the program starts here
fun main() {
    // Print "Kotlin is a modern programming language" to the console, with a trailing newline
    println("Kotlin is a modern programming language")
    // Print "It runs on the JVM and beyond" to the console, with a trailing newline
    println("It runs on the JVM and beyond")
}

Why Kotlin Was Created

JetBrains ने रोज़ Java लिखते समय उन्हें झेलनी पड़ी दिक्कतों को ठीक करने के लिए Kotlin बनाई, जैसे verbose boilerplate और null pointer exceptions का जोखिम।

Kotlin Java के साथ पूरी interoperability बनाए रखती है जबकि सुरक्षित defaults और कहीं ज़्यादा संक्षिप्त syntax जोड़ती है।

उदाहरण: Why Kotlin Was Created

markup
// Entry point: execution of the program starts here
fun main() {
    // Declare a read-only variable `goals`, set to `listOf("conciseness", "safety", "interoperability")`
    val goals = listOf("conciseness", "safety", "interoperability")
    // Loop over `goals`, binding each item to `goal`
    for (goal in goals) {
        // Print "Design goal: $goal" to the console, with a trailing newline
        println("Design goal: $goal")
    }
}

Where Kotlin Is Used

Android app development के लिए Kotlin पसंदीदा language है, लेकिन इसका उपयोग server-side backends (Ktor और Spring जैसे frameworks के साथ), iOS और Android के बीच share किए multiplatform mobile code के लिए, और general scripting के लिए भी होता है।

उदाहरण: Where Kotlin Is Used

markup
// Entry point: execution of the program starts here
fun main() {
    // Declare a read-only variable `usedFor`, set to `listOf("Android apps" to "Google apps", "Backend" to "Ktor servers", "Scripting" to "build scripts")`
    val usedFor = listOf("Android apps" to "Google apps", "Backend" to "Ktor servers", "Scripting" to "build scripts")
    for ((area, example) in usedFor) {
        // Print "$area: $example" to the console, with a trailing newline
        println("$area: $example")
    }
}

Compiled on the JVM

Kotlin source code चलने से पहले JVM bytecode में compile होता है, बिल्कुल Java की तरह।

यह compiler को program चलने से पहले ही type errors जैसी कई गलतियां पकड़ने देता है, और यह Kotlin को बिना किसी अतिरिक्त काम के Java code को call करने देता है और उल्टा भी।

Note: kotlinc file.kt -include-runtime -d app.jar चलाना फिर java -jar app.jar दो तेज़ steps में compile और run करता है।

उदाहरण: Compiled on the JVM

markup
// Entry point: execution of the program starts here
fun main() {
    // Print "This code is compiled to JVM bytecode" to the console, with a trailing newline
    println("This code is compiled to JVM bytecode")
    // Print "The compiler already checked it for errors" to the console, with a trailing newline
    println("The compiler already checked it for errors")
}
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. यह मान लेना कि Kotlin सिर्फ Android apps के लिए है और इसे backend, scripting, या साधारण command-line programs के लिए उपयोग नहीं किया जा सकता।
  2. Kotlin को Java के साथ confuse करना; Kotlin एक अलग, नई language है जिसका अपना syntax है भले ही यह एक ही JVM पर चलती हो।
  3. यह सोचना कि Kotlin code को हमेशा Android Studio चाहिए चलने के लिए, जबकि एक साधारण .kt file को terminal से compile और run किया जा सकता है।
चैप्टर सारांश
  • Kotlin एक modern, statically-typed language है जिसे JetBrains ने बनाया और 2011 में release किया।
  • यह JVM पर चलती है, JavaScript में compile होती है, और Kotlin/Native के ज़रिए natively compile होती है।
  • Google ने 2017 में Kotlin को Android development के लिए officially supported language बनाया।
  • Kotlin पूरी तरह Java के साथ interoperate करती है, इसलिए मौजूदा Java libraries को सीधे Kotlin code से उपयोग किया जा सकता है।
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.