Kotlin is a modern programming language developed by JetBrains and officially supported for Android development by Google. It is known for its concise syntax, interoperability with Java, and strong support for functional programming concepts.
In Kotlin, when writing purely Kotlin applications, the main function serves as the entry point. It is where the execution of the program begins:
kotlinCopy code
fun main() {
// Code goes here
}
The fun keyword is used to define functions in Kotlin, making it straightforward to declare and call functions within your program.
<aside> 💡 Rules Name of function should and program should be in camelCase and a verd
</aside>
Variables in Kotlin are defined using the var and val keywords, where var declares mutable variables (those whose values can change) and val declares immutable variables (constants).
Kotlin supports various data types, including:
"Hello, Kotlin!".42.3.14.2.718f.true or false.kotlinCopy code
fun main() {
val message: String = "Hello, Kotlin!" // Declaring an immutable string variable
var count: Int = 10 // Declaring a mutable integer variable
val pi: Double = 3.14159 // Declaring an immutable double variable
val isActive: Boolean = true // Declaring an immutable boolean variable
println(message)
println("Count: $count")
println("Pi: $pi")
println("Is Active? $isActive")
}
In this example: