Back to notes
What are the key features of Kotlin?
Press to flip
Key features of Kotlin include null safety, extension functions, functional programming capabilities, and support for OOP principles.
What is the syntax for a basic if statement in Kotlin?
The syntax for an if statement in Kotlin is: if (condition) { action } else { alternative action }
What is a higher order function in Kotlin?
A higher order function in Kotlin is a function that takes other functions as parameters or returns a function.
How do you use default and named parameters in Kotlin functions?
In Kotlin, default values can be assigned to function parameters. Named arguments can be used to specify the values of parameters in any order when calling the function.
How do you define a function in Kotlin?
Functions in Kotlin are defined using the 'fun' keyword followed by the function name, parameters, and body.
How can you handle nullability in Kotlin?
Kotlin handles nullability by making types non-nullable by default. Nullable types can be declared using a '?' after the type.
What are the two types of variable declarations in Kotlin and how do they differ?
In Kotlin, variables can be declared using 'var' for mutable variables and 'val' for immutable variables. 'var' allows reassignment while 'val' does not.
Give an example of a higher order function in Kotlin.
An example of a higher order function in Kotlin is a custom filter function for a List that takes a predicate function as a parameter and applies it to filter the list.
What is the purpose of data classes in Kotlin?
Data classes in Kotlin are used for modeling data. They automatically generate methods like equals, hashCode, and toString.
What year was Kotlin introduced and by which company?
Kotlin was introduced in 2011 by JetBrains.
What are the steps to set up a Kotlin project in IntelliJ IDEA?
To set up a Kotlin project, install IntelliJ IDEA, create a new project, select Kotlin and the JVM target, name the project, and add a Kotlin file.
How do you work with collections such as Lists and Maps in Kotlin?
In Kotlin, collections like Lists and Maps can be manipulated using functional operations such as map and filter.
How do you create a 'Hello World' program in Kotlin?
Define a 'main' function with 'println("Hello Kotlin")' to output 'Hello Kotlin'.
Describe how to use 'when' statements in Kotlin.
A 'when' statement in Kotlin is used to replace switch statements. It checks a variable against various conditions and executes the corresponding block of code.
How do you make a class inheritable in Kotlin?
In Kotlin, you use the 'open' keyword on a class to allow it to be inherited.
What is the primary use of Kotlin?
Kotlin is primarily used for Android development.
Previous
Next