Kotlin (Language)
Kotlin is a next-generation programming language developed by JetBrains. It combines both object-oriented and functional features. It's focused on interoperability, safety, clarity and tooling support. It can be used for server-side, desktop or mobile apps.
It's statically typed like Java, C, and C++. It's also fully compatible with Java but has a much simpler syntax. Google officially supports it for the Android platform and therefore Android apps can be written in Kotlin. Kotlin has multiplatform support, which means that code can be reused across Android, iOS or Web.
It's open sourced under Apache 2 License. It's managed by the Kotlin Foundation.
Discussion
-
In what application areas is Kotlin most suitable? Diverse set of apps can be built with Kotlin since it's a general-purpose language. It can be used to build mobile apps such as Android apps. Server-side apps can be built with Kotlin. Wherever Java is used for enterprise apps, such apps can be migrated to Kotlin. Since Kotlin can be compiled to JavaScript it can be used for web app development.
Kotlin uses two file extensions:
.kt
for object-oriented programming and.kts
for command-line scripting. This suggests that Kotlin can be used for scripting. Kotlin also has an interactive shell. This is useful for learning or clarifying doubts since results of code execution can be seen right away.In the real world, adopters of Kotlin include Pinterest, Gradle, Evernote, Corda, Coursera, Uber, Trello, Kickstarter, Square, and many more.
-
What's the difference between Kotlin and Java? While there are differences, it's important to first note that Kotlin is compatible with Java. Kotlin code can be mixed with Java and can call existing Java libraries. IDEs also support automated conversion of Java code to Kotlin code. This makes the transition from Java to Kotlin a lot easier for existing projects. Since Kotlin targets JVM, Kotlin
.kt
files compile to.jar
files.Here are some reasons why it makes sense to move to Kotlin:
- Learning Curve: Kotlin has a simpler syntax and therefore easier to learn.
- Development Environment: Kotlin has excellent IDE support, including IntelliJ IDEA and Android Studio. Compilation is fast, sometimes faster than Java. Similar support is lacking in Scala.
- Concise: Kotlin does more with less code. Strong type inference is one reason. Java has always been known for its verbosity.
- Performance: With Kotlin’s support for inline functions, code often runs faster.
- Safe: Kotlin avoids NullPointerException. Since you write less code, there's less chance of introducing errors.
- Multiplatform: Though initially created for JVM, Kotlin can be used for front-end development and even native apps.
-
Could you mention some key features of Kotlin? Here are some features of Kotlin:
- Extensions: Add extra functionality to an existing component.
- Higher-order Functions: Functions themselves can be arguments to or returned from other functions.
- Interoperable with Java: Kotlin code can be called from Java code and vice versa.
- Null Safety: Objects are null safe by default so that nasty null pointer exceptions are avoided.
- Smart Cast: Object is automatically cast to a desired type.
- Default Arguments: Java took the approach of function overloading instead.
- Named Arguments: Makes code more readable and order of arguments can be changed.
- Multi-value Returns: Returned values can be unpacked into separate variables using destructuring declaration.
- Data Class: Gets rid of the more verbose getters and setters in Java.
A JetBrains survey from 2017 showed that three features are highly requested: collection literals, Single Abstract Method (SAM) conversions for Kotlin interfaces, and truly immutable data. JetBrains makes no promise if and when these features might be available. There are also features that developers don't want: accessing private members from tests, collection comprehensions, and static members in classes.
-
What resources are available for a Kotlin beginner? Start by reading some examples in Kotlin Playground. For more in-depth information, read the official Kotlin documentation or tutorials. To learn by solving short exercises, Kotlin Koans is recommended. It's a series of exercises that will help you learn Kotlin step by step.
Kotlin style guide is an essential read. There's also a Kotlin for Android style guide.
For latest news, follow the Kotlin blog or the weekly mailing list. Links to other community resources such as podcasts, talks and Slack channels are available online.
Milestones
2011
JetBrains unveils Kotlin at the JVM Language Summit. It's a new language for the Java Virtual Machine (JVM). The team is lead by Dmitry Jemerov and they have been working on it for almost a year. Since JetBrains makes development tools, work on IDE support for Kotlin happens in parallel with language design and evolution. JetBrains engineers later comment that although Scala was popular, it wasn't as fast or simple as desired. Groovy and Clojure had different programming paradigms.
2012
2016
2017
At Google I/O 2017, Google announces support for Kotlin on Android. Until then, Android supported only Java and C++. It's mentioned that Expedia, Flipboard, Pinterest, and Square are among those already using Kotlin in production. Android support marks a turning point in Kotlin adoption. For example, by November 2017, number of lines of code on GitHub rose from 5 million to 25 millions.
2017
2018
2018
Kotlin team releases version 1.0 of Ktor, a web framework built in Kotlin. It's good for building asynchronous servers and clients in connected systems. Thanks to coroutines, complex asynchronous constructs can be expressed as sequential code. It's claimed that Ktor is already running at scale in many production systems.
Sample Code
References
- Android Developers YouTube. 2017. "Kotlin: Android Support Announced at Google I/O." June 08. Accessed 2019-01-20.
- Belov, Roman. 2018a. "Kotlin 1.3 Released with Coroutines, Kotlin/Native Beta, and more." Kotlin Blog, JetBrains, October 29. Accessed 2019-01-20.
- Belov, Roman. 2018b. "Ktor 1.0 Released: A Connected Applications Framework by JetBrains." Kotlin Blog, JetBrains, November 19. Accessed 2019-01-18.
- Breslav, Andrey. 2016. "Kotlin 1.0 Released: Pragmatic Language for JVM and Android." Kotlin Blog, JetBrains, February 15. Accessed 2019-01-20.
- Breslav, Andrey. 2017. "Kotlin Future Features Survey Results." Kotlin Blog, JetBrains, June 13. Accessed 2019-01-20.
- Cleron, Mike. 2017. "Android Announces Support for Kotlin." Android Developers Blog, May 17. Accessed 2019-01-20.
- Finley, Klint. 2017. "Kotlin: the Upstart Coding Language Conquering Silicon Valley." Wired, July 18. Accessed 2019-01-18.
- Gill, Navdeep Singh. 2017. "Overview of Kotlin and Comparison Between Kotlin and Java." XenonStack Blog, May 17. Accessed 2019-01-18.
- Heiss, Janice J. 2013. "The Advent of Kotlin: A Conversation with JetBrains' Andrey Breslav." Oracle Technology Network, Oracle, April. Accessed 2019-01-18.
- Igushkin, Sergey. 2018. "Kotlin 1.2.70 is Out!" Kotlin Blog, JetBrains, September 13. Accessed 2019-01-20.
- Jemerov, Dmitry. 2011. "Hello World." Kotlin Blog, JetBrains, July 19. Accessed 2019-01-20.
- Jemerov, Dmitry. 2017. "Kotlin 1.2 Released: Sharing Code between Platforms." Kotlin Blog, JetBrains, November 28. Accessed 2019-01-20.
- Kotlin. 2019a. "Community Overview." Kotlin. Accessed 2019-01-18.
- Kotlin. 2019b. "Kotlin Foundation." Kotlin. Accessed 2019-01-20.
- Kotlin Docs. 2018. "Working with the Command Line Compiler." October 01. Accessed 2019-01-20.
- Leiva, Antonio. 2017. "12 reasons why you should start using Kotlin for Android today (KAD 30)." July 11. Accessed 2019-01-20.
- Oreshnikova, Ann. 2012. "Kotlin Goes Open Source!" Kotlin Blog, JetBrains, February 14. Accessed 2019-01-20.
- Paul, Javin. 2018. "Top 5 Kotlin Programming Courses for Java and Android Programmers." Hacker Noon, via Medium, October 21. Accessed 2019-01-18.
- Pusher. 2018. "The State of Kotlin 2018." Pusher. Accessed 2019-01-18.
- Rai, Pankaj. 2017. "The best features of Kotlin!" AndroidPub, via Medium, May 20. Accessed 2019-01-18.
- Sharma, Avinash. 2018. "Know Why These 14 Famous Apps Migrated from Java to Kotlin." Blog, AppInventiv Technologies, June 13. Accessed 2019-01-20.
- Titus, Jason. 2017. "Google I/O 2017: Empowering developers to build the best experiences across platforms." Android Developers Blog, May 17. Accessed 2019-01-20.
- Wikipedia. 2019. "Kotlin (programming language)." Wikipedia, January 12. Accessed 2019-01-18.
Further Reading
- Saini, Ajay. 2017. "How to use Kotlin in Android Studio." Medium, May 18. Accessed 2019-01-20.
- Finley, Klint. 2017. "Kotlin: the Upstart Coding Language Conquering Silicon Valley." Wired, July 18. Accessed 2019-01-18.
- Heiss, Janice J. 2013. "The Advent of Kotlin: A Conversation with JetBrains' Andrey Breslav." Oracle Technology Network, Oracle, April. Accessed 2019-01-18.
- Zukanov, Vasiliy. 2017. "Kotlin vs Java The Whole Story." TechYourChance, September 07. Accessed 2019-01-18.
- Rai, Pankaj. 2017. "The best features of Kotlin!" AndroidPub, via Medium, May 20. Accessed 2019-01-18.
- Pusher. 2018. "The State of Kotlin 2018." Pusher. Accessed 2019-01-18.
Article Stats
Cite As
See Also
- Java (Language)
- IntelliJ IDEA
- Ktor
- Type Inference
- Static vs Dynamic Typing
- Functional Programming