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 application fun 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.jar Execute your application java -jar hello.jar If 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 JavaScript To 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.sh To install kotlin Type the command: source ~/.sdkman/bin/sdkman-init.sh sdk install kotlin To 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-headless To confirm installation type the command: kotlin -version It should return output similar to one below Kotlin 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 language Kotlin 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 language Kotlin applications must have a main method. println is used for text output just like in Java fun main() {     println("hello world") } After compiling the output should be "hello world" Basic s yntax variable declaration Variables are declared using