Skip to main content

Posts

Showing posts from January, 2018

Kotlin Idioms

Idioms Random and frequently used in kotlin. Creating Data classes in kotlin (POJOs/DTOs) Data classes are model classes which are created to hold data. In Java, we usually create POJO classes with getter and setter methods for each member variable of a class. But in Kotlin, POJO class can be created within a single line of code with keywords: 'data', 'class', 'class name' and its member variables. data class Student( val name: String, val age: Int) provides a Student class with the following functionality: - getters(and setters in case of vars) for all properties - equals() - hashCode() - toString() - copy() - object1(), object2(), ..., for all properties. Filter a list in kotlin There are several ways to filter a list in kotlin. For example: val  fruits = listOf ("Apple", "Banana", "Orange")                                                               And we will filter values matching "Ap

Kotlin Basic Syntax

Basic Syntax kotlin syntax is somewhere similar to java but there are few changes that had made easier for developers to clean and optimize their code with ease. Defining packages The package specification is similar to Java which should be at the top of the source file:  package   org.project.demo   import   java.util.*  // comment {...} Defining functions Defining function in kotlin is much easier. It is also more clear to read and understand. kotlin support for inline functions, code using lambdas often runs even faster than the same code written in Java.  Some examples: Function having two Int parameter with Int return type:    fun sum (a: Int, b: Int): Int {     return a + b } Function  with an expression body and inferred return type:   fun sum (a: Int, b: Int) = a + b Defining variables Variables in kotlin allow, as in Java, to assign values that can then be modified and used at different points in our program. The variables can be

Kotlin fun to learn

Kotlin is a programming language developed by JetBrains for modern multiplatform applications. It runs on the Java Virtual Machine(JVM) and also can be compiled to JavaScript code or use the Low Level Virtual Machine(LLVM) compiler infrastructure. It is safe, concise and fun to read and write. why kotlin ? kotlin is a statically typed programming that works in JVM, Android, JavaScript, and Native. It compiles to bytecode which makes a strong case for incorporating performance tuning into the development. some main features: 1. Open Source:  Kotlins is distributed under Apache License, Version 2.0. The kotlinc(Kotlin compiler), Intellij IDEA plugin, enhancements to basic Java libraries and build tools all are open source. 2. Interoperable with Java and Android:  It is designed with Java interoperability in mind. This means all current java and the android code works smoothly with kotlin. 3. Easy to Learn:  It is influenced by Java, Scala, Groovy, C#, JavaScript and Go