From the course: Complete Guide to Android Development with Kotlin for Beginners

Programming for Android with Kotlin

- [Instructor] Modern Android applications are developed using the Kotlin programming language. However, it's worth noting that the Android SDK was built using an open source Java implementation. So you'll find classes for common Java APIs like java.lang, java.text and java.io When creating a new project in Android Studio, the default configuration uses Jetpack Compose and the Kotlin programming language. Kotlin's type system puts null-ability front and center, a known cause of many programming errors. Its compiler enforces that variables that cannot hold null values will cause a compilation error if you attempt to set them to null, just like we see here. Conversely, if you explicitly declare that the variable can be null-able, you're good to go. This can prevent you from experiencing the dreaded null pointer exceptions that Android is notoriously known for. Kotlin also helps with readability in your Android code. Android tends to make liberal use of callbacks and listeners, and here's an example of setting a click listener on a floating action button in Java. And here it is again in Kotlin, much more concise and easier to read. And with Jetpack Compose, it's streamlined even more with the use of lambdas. Kotlin also allows you to extend the functionality of existing classes even when they're not your own. For instance, one common thing we do often in Android is to set the padding on a particular view. Here's how that looks without the use of extensions. However, since this bit of code is so common, the Android team created an extension property on the integer class, just like you see here. Now, don't get caught up in the syntax. The key takeaway is that there's a shortcut for defining the padding available. Now, instead of calling DP with the use of the toFloat method, we have a simpler use of the DP extension property. Now, this is a simple example, but we'll be using loads of pre-written extension properties and methods when we're developing our Android app. Yes, when it comes to developing on Android, Kotlin has a lot to offer.

Contents