Kotlin
-
Kotlin let, run, also, apply, with
In this tutorial, we’ll be implementing some of the important standard library functions available in Kotlin. The kotlin-stdlib provides us with useful higher order functions implementing idiomatic patterns. We’ll see how they make programming in Kotlin so easier and faster. The functions that we’re going to discuss below are: let run also apply with Kotlin let let takes the object it is invoked upon as the parameter and returns the result of the lambda expression. Kotlin let is a scoping…
-
Kotlin Interview Questions
Kotlin is the latest JVM programming language from the JetBrains. Google has made it the official language for Android Development along with Java. Developers say it addresses the issues faced in Java programming. I have written a lot of Kotlin tutorials and here I am providing important kotlin interview questions. Kotlin Interview Questions Here I am providing Kotlin Interview Questions and Answers that will help you in your Kotlin Interviews. These Kotlin interview questions are good for beginners as well…
-
Android Spinner using Kotlin
In this tutorial, we’ll be discussing and implementing Spinners in our Android Application using Kotlin. Android Spinner is used to create a drop-down list on the screen. What will you learn? Creating Spinners through XML and Programmatically Setting a prompt on the Spinner. Creating a custom layout for the Spinner. Handling Click Listeners and Display a Toast message. Preventing the Click Listener from being fired automatically for the first time. What is Android Spinner? Spinners are like a drop-down menu…
-
Kotlin print(), println(), readLine(), Scanner, REPL
Today we will learn how to use Kotlin print functions and how to get and parse user input from console. Furthermore, we’ll look into Kotlin REPL. Kotlin Print Functions To output something on the screen the following two methods are used: print() println() The print statement prints everything inside it onto the screen. The println statement appends a newline at the end of the output. The print statements internally call System.out.print. The following code shows print statements in action: fun…
-
Android Intent Handling Between Activities Using Kotlin
In this tutorial, we’ll be discussing Android Intents and implement them using Kotlin in our application. What Will You Learn? What are Intents? Types Of Intents? Using Intents Between Activities Sending Data Using Android Intents Using Parcelable and Serializable to pass objects Creating shorthand intents Android Intents As the name says Intent is something that’s used to perform some action with respect to the flow of the android application. Intents can be used to: Starting a new activity and passing…
-
Kotlin Class – Kotlin Constructor
In this tutorial, we’ll be discussing the Object Oriented Programming concepts of Kotlin. We’ll discuss Kotlin Class in detail. We will also look at kotlin constructors, access modifiers and abstract class. Kotlin Class A class is a blue print defined which groups functions and properties. Classes in Kotlin are defined using the keyword class followed by the class name. The body goes inside the curly braces. class FirstClass { } An instance of the class is instantiated in the following…
-
Kotlin Data Class
In this tutorial, we’ll look at Kotlin Data Class. If you haven’t read the Kotlin Classes post, we recommend you to do so before proceeding. Kotlin Data Class Do you get tired of writing thousands of lines of code for your POJO data classes in Java? Every Java Programmer at some stage must have taken a note of the number of lines of code they need to write for classes that just need to store some data. Let’s see how…
-
Kotlin Sealed Class
In this tutorial, we’ll be looking into Kotlin Sealed Class. What are they? What’s their use? We’ll be addressing all of these things below. Kotlin Sealed Class In layman terms, as the name suggests, sealed classes are sealed or closed, hence making them restricted. Sealed classes are used for representing restricted class hierarchies wherein the object or the value can have value only among one of the types, thus fixing your type hierarchies. Sealed classes are commonly used in cases,…
-
Kotlin Visibility Modifiers – public, protected, internal, private
In this tutorial, we’ll be discussing the various Visibility Modifiers available in Kotlin programming. Kotlin Visibility Modifiers Visibility Modifiers are modifiers that when appended to a class/interface/property/function in Kotlin, would define where all it is visible and from where all it can be accessed. The setters of properties in Kotlin can have a separate modifier from the property. The getters can’t have a visibility modifier defined. They use the same modifier as that of the property. Following are the visibility…