Posts

The var & val Of Kotlin

The Var and Val of Kotlin There can be many versions of understanding for this topic depending on how you imply to use them. Lets start with basics. Now apparently we tend to somehow understand that names are given for a reason. In our case here it is 'var' & 'val'. 'Var' can be referred as variables. Now variables as names suggest can be varying in your code journey starting to end. I hope all this is making some sense here. Coming to 'val' that can be referred as value. Now this will not change, throughout  the code value will be same.  According to the supporting document, var is mutable sure, but that does not imply val is immutable. In more simple words, 'val' is read-only variable.  What happens if you try to change the value of 'val' variable?  fun main(args: Array<String>) { val marksInMaths = 74 print("Scored Marks in Mathematics : "+marksInMaths) //now change the value m

Remove findViewById in Kotlin-Android

Remove findViewById in Kotlin From the newbie to the oldest developers in Android development knows the use of findViewById(). It is by far the commonest method used. When using this we associate a link between the XML  view to the object view in Java file. Let me remind the terminology for this, well this exactly what we refer to as View Binding.  In Kotlin, view binding is far more feasible and easy, as we got here a new plugin to add, and whoosh no findViewById() to remember every time we create a new view object. All you need to do is add a line in your 'build.gradle' file and its done.  apply plugin: 'kotlin-android-extensions' Now, how do we use this? import kotlinx.android.synthetic.main.activity_main.* class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) btnNextScreen.setOnClickListener{ v

Kotlin Beginners Guide

Kotlin The New Language for Android Development Kotlin is a new official language for Android by Google. After, literally drowning in Android language for so many years, we developers have to learn a new language in process to be competitive in market. Anyways, it is what it is.  Why a new Language ? I don't know how many of you have thought but I have been thinking a lot why a new language on whole? Always we have used Java for android development, but that doesn't make it our best choice. Since Java 8, developers are trying to fill the gap from previous versions to new versions, but android on whole doesn't support Java 8 fully. Kotlin relatively new language based on JVM (Java Virtual Machine) enables us to follow a new horizon of development. Kotlin is compatible from latest JDK to JDK6 , meaning Kotlin application can run from older devices to new devices. Having similar byte code structure enables Kotlin applications to run as fast as Java. Kotlin enables to