AnyCompiler

Aapka Pehla Kotlin Program

Har Kotlin program ko ek main() function chahiye — yahi se execution shuru hota hai. Java ke ulat, isse kisi class ke andar rehne ki zaroorat nahi, aur isse public static void mark karne ki bhi zaroorat nahi — Kotlin ka compiler ye sab background mein khud generate kar deta hai.

Pehle compiling hoti hai

Jab aap run dabate ho, compiler pehle aapki poori file check karta hai aur use JVM bytecode mein compile karta hai, tab jaake ek bhi line execute hoti hai. Agar kahin bhi type error ya syntax mistake ho, to kuch bhi run nahi hota — output ke jagah aapko compiler error milta hai.

Comments

Comments zyadatar C-family languages jaisa hi kaam karte hain: // ke baad line par jo kuch bhi likha ho wo completely ignore ho jata hai — iska maqsad sirf ye hota hai ki baad mein code padhne wale insaan ko samajh aaye ki kuch is tarah kyun likha gaya hai.

Khud run karo

Ye hai ek chhota program jisme ek comment aur do println calls hain. Ye actually execute kiya gaya tha neeche dikhaye gaye output ko lane ke liye — example ke neeche diye button se text badal kar khud run karke dekho.

fun main() {
    // This is a comment -- ignored by the compiler
    println("Hello, world!")
    println("Learning Kotlin one step at a time.")
}
Output
Hello, world!
Learning Kotlin one step at a time.

Aage: variables aur types — val versus var, aur Kotlin ke primitive types.

Practice exercise

Apne code ke upar ek comment add karo, phir "Learning Kotlin one step at a time." print karo.