Skip to content
Career & LeadershipCarrera y liderazgo

Kotlin Interview Questions. Part 1Preguntas de entrevista de Kotlin. Parte 1

ByPor David Cruz Anaya, Senior Mobile & Applied AI Engineer (Android, Kotlin Multiplatform, product AI)Ingeniero sénior de móvil e IA aplicada (Android, Kotlin Multiplatform, IA de producto)

Updated 25 January 2026Actualizado el 25 de enero de 20264 min read4 min de lectura
AndroidMobile DevelopmentKotlinCareerInterview Prep
Kotlin Interview Questions. Part 1
Share:Compartir:

Kotlin logo before a river

These are 15 beginner Kotlin questions, the first part of the series, starting from the basics. I have interviewed Android developers. An interview will not ask all of them. Each answer below includes a short example.

1. What is Kotlin?

Kotlin is a statically typed programming language created by JetBrains, with zero-cost Java interoperability, and open source under the Apache 2 OSS license. It targets the Java Virtual Machine (JVM), Android, and a web browser.

2. How to declare a Variable?

Variables in Kotlin are declared with var or val.

val name = "David" //IMMUTABLE
var surname = "Cruz" //MUTABLE

3. What is the difference between var and val declarations?

The difference is that val is immutable, while var can be reassigned to another value of the same type. Example:

val name = "David"
name = "Roberto" //This is NOT permitted

var age = 39
age = 40 //This is permitted

4. Can you declare the Type of a variable beforehand?

Yes, after using the declaration and the name of your choice, you can use a colon mark following the type before the equals mark. Some examples are the following:

val name: String = "David" //String (chain)
val age: Int = 28 //Integer (Numbers)
val temp: Double = 37.1 //Double (decimal numbers)
val isMale: Boolean = true //Boolean (true or false)

5. How to convert a String into an Integer type? and an Integer into a String type?

A valid number string converts with toInt(). An integer converts to a string with toString(). For example:

// Int to String
val numText: String = "909"
val num: Int = numText.toInt()

println(num) //Output: 909
println(num is Int) //Output: true

// String to Int
val age: Int = 34
val ageText: String = age.toString()

println(ageText) //Output: 34
println(ageText is String) //Output: true

6. What is a constant?

Constants in Kotlin are used to define a variable that has a constant value using the declaration const.

//Initials of Java Virtual Machine
const val INITIALS = "JVM"

7. What is the difference between val and const val declarations?

Both are immutable. const val is set at compile time. val on its own is set at runtime. const cannot be used with var, and it cannot be used on a local variable.

8. What is the entry point in a Kotlin project?

The entry point is the function main with an array of Strings as an argument.

fun main(args: Array<String>) {
    println("Hello World!")
}

// Output: Hello World!

9. What usability have the array of strings passed as a parameter in the entry point?

args: Array<String> passed as a parameter in the entry point is used to retrieve the command line arguments.

10. What is Null Safety in Kotlin?

Null safety is how Kotlin avoids null pointer exceptions. A type is nullable only when it is marked, for example String?, Int?, Double?, Boolean?, Char?.

var age: Int? = 45 // Nullable
age = null //This IS permitted

var temp: Double = 40.1
temp = null //This is not permitted

These types can be used as wrapper types to hold null values. If on retrieving the value, the value is null, we can choose to ignore it and use a different value instead by using an Elvis operator (?:)

var name: String? = "David"
println(name ?: "No name")
//Output: David

name = null
println(name ?: "No name")
//Output: No name

11. Are variables Nullable by default in Kotlin?

No, if you declare a variable without specifying the type, the variable will be set to the type detected but non-nullable. Variables with nullable type must be declared beforehand.

var name = "David" //Similar as var name: String = "david"
name = null //This IS NOT permitted :(

var name: String? = "David"
name = null //This IS Permitted :)

12. What is an Elvis Operator?

Elvis operator is used to return a non-null value in the case scenario where the first or left value is null and is written ?:. For example:

val firstName: String? = null
val secondName: String? = null
var thirdName: String? = "David"
println(firstName ?: secondName ?: thirdName)
//Output: David

Explanation: As the first and second values are null it jumps into the third value printing in the console output the word “David”

Fact: You can concatenate all Elvis operations as you like, however, it is intended to use it only in case the first value is null to give a non-null default value.

13. Kotlin has interoperability with Java. Does Kotlin allow us to use primitive types?

No, we cannot use or declare primitive types at the language level, as in Kotlin, all are Objects. However, the JVM bytecode where it is compiled has them.

14. For what are the double exclamation marks !! used?

The double exclamation marks (!!) force-unwrap a nullable value. Use them with caution: if the value is null, the program crashes at runtime.

var city: String? = "London"
println(city!!)
//Output: London

city = null
print(city!!)
//Output: Exception in thread "main" java.lang.NullPointerException

15. How are functions declared?

functions in Kotlin are declared by the keyword fun, and the function can return or not a value. If the function returns a value, that type must be declared after the parenthesis and before the curly brackets with a colon.

In Kotlin, a function that does not return a value has the type Unit. Writing Unit as the return type is redundant.

fun sayHello(paramOne: String, paramTwo: String): String {
  return "Hello $paramOne $paramTwo"
}
println(sayHello("David", "Cruz"))
//Output: "Hello David Cruz"

// Function that return Unit (Not Return value)
fun nameOfFunction(paramOne: String, paramTwo: String) {
  println(sayHello("David", "Cruz"))
}
println(nameOfFunction("David", "Cruz"))
//Output: "Hello David Cruz"

/* FOR REFERENCE ONLY
fun nameOfFunction(paramOne: String, paramTwo: String): Unit {
  println(sayHello("David", "Cruz"))
}
*/

This is the end of the first part of the Kotlin Interview Questions series.

If you found these 15 questions easy, that is a good sign; on every part, the complexity will increase, so keep an eye on the next episode :)

Happy Interview!

Let’s Keep in touch:
davthecoder Web: https://www.davthecoder.com
Medium Blog: https://davthecoder.medium.com/
Twitch: https://www.twitch.tv/davthecoder
GitHub: https://github.com/davthecodercom
Instagram: https://www.instagram.com/davthecoder
Twitter: https://twitter.com/davthecoder
Youtube: https://youtube.com/@davthecoder
Support me on Patreon! https://www.patreon.com/davthecoder


Logotipo de Kotlin ante un río

Estas son 15 preguntas de Kotlin para principiantes, la primera parte de la serie, empezando por lo básico. He entrevistado a desarrolladores Android. Una entrevista no las pregunta todas. Cada respuesta de abajo incluye un ejemplo corto.

1. ¿Qué es Kotlin?

Kotlin es un lenguaje de programación de tipado estático, creado por JetBrains, con interoperabilidad con Java a coste cero y de código abierto bajo la licencia Apache 2 OSS. Tiene como destino la Java Virtual Machine (JVM), Android y un navegador web.

2. ¿Cómo se declara una variable?

Las variables en Kotlin se declaran con var o val.

val name = "David" //IMMUTABLE
var surname = "Cruz" //MUTABLE

3. ¿Cuál es la diferencia entre las declaraciones var y val?

La diferencia es que val es inmutable, mientras que var se puede reasignar con otro valor del mismo tipo. Ejemplo:

val name = "David"
name = "Roberto" //This is NOT permitted

var age = 39
age = 40 //This is permitted

4. ¿Se puede declarar el tipo de una variable de antemano?

Sí: tras usar la declaración y el nombre que elijas, puedes poner dos puntos seguidos del tipo, antes del signo igual. Algunos ejemplos son los siguientes:

val name: String = "David" //String (chain)
val age: Int = 28 //Integer (Numbers)
val temp: Double = 37.1 //Double (decimal numbers)
val isMale: Boolean = true //Boolean (true or false)

5. ¿Cómo se convierte un String en un tipo Integer? ¿Y un Integer en un tipo String?

Un string que sea un número válido se convierte con toInt(). Un entero se convierte a string con toString(). Por ejemplo:

// Int to String
val numText: String = "909"
val num: Int = numText.toInt()

println(num) //Output: 909
println(num is Int) //Output: true

// String to Int
val age: Int = 34
val ageText: String = age.toString()

println(ageText) //Output: 34
println(ageText is String) //Output: true

6. ¿Qué es una constante?

Las constantes en Kotlin se usan para definir una variable que tiene un valor constante mediante la declaración const.

//Initials of Java Virtual Machine
const val INITIALS = "JVM"

7. ¿Cuál es la diferencia entre las declaraciones val y const val?

Las dos son inmutables. const val se establece en tiempo de compilación. val por sí sola se establece en tiempo de ejecución. const no se puede usar con var, ni en una variable local.

8. ¿Cuál es el punto de entrada en un proyecto de Kotlin?

El punto de entrada es la función main, con un array de String como argumento.

fun main(args: Array<String>) {
    println("Hello World!")
}

// Output: Hello World!

9. ¿Qué utilidad tiene el array de strings que se pasa como parámetro en el punto de entrada?

args: Array<String>, pasado como parámetro en el punto de entrada, se usa para recuperar los argumentos de la línea de comandos.

10. ¿Qué es la seguridad ante nulos (Null Safety) en Kotlin?

La seguridad ante nulos es la forma que tiene Kotlin de evitar las null pointer exceptions. Un tipo es anulable solo cuando se marca, por ejemplo String?, Int?, Double?, Boolean?, Char?.

var age: Int? = 45 // Nullable
age = null //This IS permitted

var temp: Double = 40.1
temp = null //This is not permitted

Estos tipos se pueden usar como tipos wrapper para contener valores nulos. Si, al recuperar el valor, este es nulo, podemos elegir ignorarlo y usar otro valor en su lugar mediante el operador Elvis (?:).

var name: String? = "David"
println(name ?: "No name")
//Output: David

name = null
println(name ?: "No name")
//Output: No name

11. ¿Las variables son anulables por defecto en Kotlin?

No. Si declaras una variable sin especificar el tipo, la variable quedará con el tipo detectado, pero no anulable. Las variables de tipo anulable hay que declararlas de antemano.

var name = "David" //Similar as var name: String = "david"
name = null //This IS NOT permitted :(

var name: String? = "David"
name = null //This IS Permitted :)

12. ¿Qué es el operador Elvis?

El operador Elvis se usa para devolver un valor no nulo en el caso en el que el primer valor, el de la izquierda, es nulo, y se escribe ?:. Por ejemplo:

val firstName: String? = null
val secondName: String? = null
var thirdName: String? = "David"
println(firstName ?: secondName ?: thirdName)
//Output: David

Explicación: como el primer y el segundo valor son nulos, salta al tercer valor e imprime en la salida de la consola la palabra «David».

Dato: puedes concatenar todas las operaciones Elvis que quieras; sin embargo, está pensado para usarse solo cuando el primer valor es nulo, para dar un valor por defecto no nulo.

13. Kotlin tiene interoperabilidad con Java. ¿Kotlin nos permite usar tipos primitivos?

No: no podemos usar ni declarar tipos primitivos a nivel de lenguaje, ya que en Kotlin todo son objetos. Sin embargo, el bytecode de la JVM en el que se compila sí los tiene.

14. ¿Para qué se usan los dos signos de exclamación !!?

Los dos signos de exclamación (!!) desenvuelven a la fuerza un valor anulable. Úsalos con precaución: si el valor es nulo, el programa falla en tiempo de ejecución.

var city: String? = "London"
println(city!!)
//Output: London

city = null
print(city!!)
//Output: Exception in thread "main" java.lang.NullPointerException

15. ¿Cómo se declaran las funciones?

Las funciones en Kotlin se declaran con la palabra clave fun, y la función puede devolver un valor o no. Si la función devuelve un valor, ese tipo debe declararse después del paréntesis y antes de las llaves, con dos puntos.

En Kotlin, si la función no devuelve un valor, se considera que esta función devuelve el tipo Unit. Sin embargo, añadir Unit como valor de retorno es redundante.

fun sayHello(paramOne: String, paramTwo: String): String {
  return "Hello $paramOne $paramTwo"
}
println(sayHello("David", "Cruz"))
//Output: "Hello David Cruz"

// Function that return Unit (Not Return value)
fun nameOfFunction(paramOne: String, paramTwo: String) {
  println(sayHello("David", "Cruz"))
}
println(nameOfFunction("David", "Cruz"))
//Output: "Hello David Cruz"

/* FOR REFERENCE ONLY
fun nameOfFunction(paramOne: String, paramTwo: String): Unit {
  println(sayHello("David", "Cruz"))
}
*/

Aquí termina la primera parte de la serie de preguntas de entrevista de Kotlin.

Si estas 15 preguntas te han parecido fáciles, es buena señal; en cada parte la complejidad irá subiendo, así que no pierdas de vista el próximo episodio :)

¡Feliz entrevista!

Sigamos en contacto:
Web de davthecoder: https://www.davthecoder.com
Blog de Medium: https://davthecoder.medium.com/
Twitch: https://www.twitch.tv/davthecoder
GitHub: https://github.com/davthecodercom
Instagram: https://www.instagram.com/davthecoder
Twitter: https://twitter.com/davthecoder
Youtube: https://youtube.com/@davthecoder
¡Apóyame en Patreon! https://www.patreon.com/davthecoder

Share:Compartir:

CommentsComentarios

Loading comments…Cargando comentarios…