Posts

Showing posts with the label Kotlin

Lambadas in kotlin programming language

Lambadas are similar to arrow functions in JavaScript they are a short alternative method to declare functions in kotlin programing language, You can create a function expression as;
val double = {num: Int -> num * 2} val cube = { num: Int -> num * num * num} val square = {num: Int ->
    val product = num * num
    product }
The last expression in a lambada is considered as a return value; Parameters can be omitted, for a single parameter lambada the value of the omitted parameter is in the variable 'it'

How to interpolate strings in Kotlin programming language

Image
Kotlin programming language has string interpolation similar to template literals in JavaScript
For JavaScript You can write as;
var passage = `I'm going todo a ${chore}`
In Kotlin you can do string interpolation as;
var passage = "I'm going todo a $chore"
Interpolating expressions in kotlin is done as;
var state = "I'm done with ${numChores()} chores"

Hello world application in Kotlin

Kotlin Hello World Application To get started open your editor and type the snippet of code below fun main() {
    println("Hello, World!")
}in kotlin main is the entry point function of an applicationfun keyword is used for declaring functions it acts like function does in JavaScript.Compile your application into jar
kotlinc hello.kt -include-runtime -d hello.jarExecute your application
java -jar hello.jarIf everything went well you should see "Hello World" output from your terminal

How to install Kotlin programming language

Kotlin is a programming language that is statically typed runs on the JVM and can compile to JavaScriptTo install kotlin using the Software Development Kit on Debian Ubuntu or Linux environment.First install the SDK using
Command:wget -O sdk.install.sh "https://get.sdkman.io"
bash sdk.install.shTo install kotlin Type the command:source ~/.sdkman/bin/sdkman-init.sh
sdk install kotlinTo install Java development kit (JDK) a vital dependency used for execution and compilation of kotlin code.
Type the command:sudo apt-get install openjdk-8-jre-headlessTo confirm installation type the command:kotlin -versionIt should return output similar to one belowKotlin version 1.3.61-release-180 (JRE 1.8...)

Introduction to Kotlin programing language

Kotlin is an open source statically typed programming language named after an island just like Java was named after an Indonesian island.Kotlin runs on the JVM and can compile to JavaScript.Uses for kotlin programming languageKotlin is a preferred programming language for Android application development second after Java programming language.Kotlin can be used for artificial intelligence and data science research applications.Because of its speed kotlin is a well suited programing language for web server application development.On rare occasions you can use kotlin to develop client side application simply because it can compile to JavaScript.Hello world application in kotlin programming languageKotlin applications must have a main method.
println is used for text output just like in Javafun main() {
    println("hello world")
}After compiling the output should be "hello world"Basic syntax variable declaration
Variables are declared using
'var' for mutable …