1) What is Kotlin?
Kotlin is a statically-typed programming language which runs on the JVM. It can be compiled either using Java source code and LLVM compiler.
2) Who is the developer of Kotlin?
Kotlin was developed by JetBrains.
3) Why you should switch to Kotlin from Java?
Kotlin language is quite simple compared to Java. It reduces may redundancies in code as compared to Java. Kotlin can offer some useful features which are not supported by Java.
4) Tell three most important benefits of using Kotlin?
5) Explain the use of extension functions
Extension functions are beneficial for extending class without the need to inherit from the class.
6) What does ‘Null Safety’ mean in Kotlin?
Null Safety feature allows removing the risk of occurrence of NullPointerException in real time. It is also possible to differentiate between nullable references and non-nullable references.
7) Why is Kotlin interoperable with Java?
Kotlin is interoperable with Java because it uses JVM bytecode. Compiling it directly to bytecode helps to achieve faster compile time and makes no difference between Java and Kotlin for JVM.
8) Is there any Ternary Conditional Operator in Kotlin like in Java?
No there is no ternary conditional operator in Kotlin language.
9) How can you declare a variable in Kotlin?
value my_var: Char
10) How many constructors are available in Kotlin?
Two types of constructors available in Kotlin are:
11) Can you tell me what kinds of programming types does Kotlin support?
12) Give me name of the extension methods Kotlin provides to java.io.File
13) How can you handle null exceptions in Kotlin?
Elvis Operator is used for handling null expectations in Kotlin.
14) What are some of the features which are there in Kotlin but not In Java?
Here, are few important Kotlin features that Java doesn’t have:
15) Explain the use of data class in Kotlin?
Data class holds the basic data types. It does not contain any functionality.
16) Can we migrate code from Java to Kotlin?
Yes, JetBrains IDEA provides an inbuilt tool to migrate code from java to Kotlin.
17) Does Kotlin allow macros?
No. Kotlin does not offer support for macros because the developers of Kotlin find it difficult to include it in the language.
18) Tell me the default behavior of Kotlin classes?
In Kotlin all classes are final by default. That’s because Kotlin allows multiple inheritances for classes, and an open class is more expensive than a final class.
19) Does Kotlin support primitive Datatypes?
No, Kotlin does not provide support for primitive Data types like in Java.
20) What is Ranges operator in Kotlin?
Ranges operator helps to iterate through a range. Its operator form is (..) For Example
for (i in 1..15) print(i)
It will print from 1 to 15 in output.
21) Can Kotline offer any additional functionality for standard Java packages or standard Java classes?
Kotlin programs can run on standard JVM like any another compiled Java code. It allows JVM to compile any program to byte-code. It is accessible using Java Virtual Machine. Therefore, Kotlin is almost similar to Java. Moreover, Kotlin applications can be built with parts of Java code.
22) Give a syntax for declaring a variable as volatile in Kotlin?
Volatile var x: Long? = null
23) What is the use of abstraction in Kotlin?
Abstraction is the most important concept of Objected Oriented Programming. In Kotlin, abstraction class is used when you know what functionalities a class should have. But you are not aware of how the functionality is implemented or if the functionality can be implemented using different methods.
24) How to compare two strings in Kotlin?
Compares string in Kotlin are possible in the following ways:
You can use ah operator for comparison of two string. In Kotlin == operator is used.
Syntax of compareTo() function is given below :
fun String.compareTo( other: String, ignoreCase: Boolean = false ): Int
Another code example
fun main(args: Array & lt; String & gt;) { val x: String = "Kotlin is simple" val y: String = "Kotlin language is" + " easy" if (x == y) { println(" x and y are similar.") } else { println(" x and y are not similar.") } }
25) What does this code do?
bar { System.out.println("Guru99!") }
The code passes lambda function that prints “Guru99!” as an argument into function bar()
View Comments
Thanks so much!
That’s because Kotlin allows multiple inheritances for classes Seriously?
thank you man