How well do you know your Kotlin trivia?
Our pub quiz series continues with another look at a new programming language. This time, we’re testing your knowledge about Kotlin, the darling of Android that was recently promoted to a first-class language status. Do you know everything there is to know about this fresh-faced static language?
After the recent Google I/O announcement of Kotlin being an official language for Android, it has rose tremendously in popularity. Developers love Kotlin because it is expressive, safe, concise and fun to code with. Kotlin plays well with the Java programming language and the effortless interoperation between the two languages has been a large part of Kotlin’s appeal.
Let’s get down to business and test your knowledge of Kotlin trivia!
1. Who is the creator of Kotlin?
2. Which open source license is Kotlin released under?
a) MIT License (MIT)
b) GNU General Public License (GPL)
c) Apache License 2.0 (Apache 2.0)
d) FreeBSD License (BSD-2-Clause)
3. Does Kotlin work only for Java?
4. Is Kotlin backward-compatible?
5. Does Kotlin allow macros?
6. Which of these is used to handle null exceptions in Kotlin?
b) Sealed Class
c) Elvis Operator
d) Lambda function
7. What is the default behavior of Kotlin classes?
a) All classes are public.
b) All classes are sealed.
c) All classes are final.
d) All classes are abstract.
8. Which of these is true for Kotlin variables?
a) val corresponds to final variable in Java.
b) var cannot be changed.
c) val can be changed.
d) All variables are immutable by default.
SEE MORE: Why learn Kotlin [Infographic]
1. b) JetBrains. Kotlin was created by JetBrains, a company renowned for creating development tools for professionals.
2. c) Apache License 2.0 (Apache 2.0). JetBrains is open sourced Kotlin under Apache 2 License. You can edit and distribute all development code and tools related to Kotlin as you please, without renaming it as your own intellectual property.
4. a) Yes. However, the compatibility exists only until a major release of Kotlin. So, if the current version of Kotlin is 1.1.4, the deprecation takes place in 1.7, it is then elevated to an error in 1.8 and the deprecated code is deleted after 2.0.
5. b) No. It’s hard to optimize and test code containing macros. Hence, the developers of Kotlin decided not to include it in the language.
6. c) Elvis Operator. You can use Elvis operator (?:) in Kotlin to say “if object is not null, use it, otherwise use some non-null value”.
7. c) All classes are final. All Kotlin classes are final by default. This is because the initial design of Kotlin included multiple inheritance for classes, and an open class was a lot more expensive bytecode-wise than a final class.
8. a) val corresponds to final variable in Java. Both val and var are used to create variables in Kotlin. However, using val makes a variable immutable, i.e. you cannot change its value once initialized. This corresponds to final variable in Java.
How well did you do? Do you know your Kotlin trivia?
0-3 correct: You’re just a Kotlin beginner. Time to go through a comprehensive tutorial on Kotlin and do a bit more studying. Head over to Programiz for Kotlin tutorials.
4-5 correct: You’re pretty solid in your Kotlin trivia, but you still might need to pay a little more attention to the details.
6-7 correct: Nice! You really know your stuff!
8 correct: You are a Kotlin master.
Programming Pub Quiz
Have you tried our other pub quizzes? Test your knowledge of other programming languages!