Kotlin (programming language): Difference between revisions

Content deleted Content added
Tags: Mobile edit Mobile web edit
Jooja (talk | contribs)
mNo edit summary
 
(16 intermediate revisions by 7 users not shown)
Line 3:
{{Infobox programming language
| name = Kotlin
| logo = Kotlin logo (2021-present).svg
| logo size = 230px
| paradigm = [[Multi-paradigm programming language|Multi-paradigm]]: [[Object-oriented programming|object-oriented]], [[Functional programming|functional]], [[Imperative programming|imperative]], [[Block (programming)|block structured]], [[Declarative programming|declarative]], [[Generic programming|generic]], [[Reflective programming|reflective]], [[Concurrent computing|concurrent]]
Line 51:
 
==History==
[[File:Kotlin Mascot 2D no. 1Kodee-mascot-regular.svg|thumb|upright=0.5|AKotlin 2Dmascot picturenamed ofKodee the(regular Kotlin mascotversion)]]
[[File:Kotlin Mascot 3D no. 5Kodee-mascot-petite.pngsvg|thumb|upright=0.5|AKotlin 3Dmascot picturenamed ofKodee the(petite Kotlin mascotversion)]]
 
=== Name ===
Line 80:
* functions and methods support [[default argument]]s, [[variadic function|variable-length argument]] lists and [[Named parameter|named argument]]s
 
Kotlin 1.3 added support for contracts,<ref>{{Cite web|url=https://kotlinlang.org/docs/reference/whatsnew13.html|title=What's New in Kotlin 1.3 - Kotlin Programming Language|website=Kotlin|access-date=4 April 2020|archive-date=22 August 2023|archive-url=https://web.archive.org/web/20230822164600/https://kotlinlang.org/docs/reference/whatsnew13.html|url-status=live}}</ref> which are stable for the standard library declarations, but still experimental for user-defined declarations. Contracts are inspired by [[Eiffel (programming language)|Eiffel's]] [[design by contract]]<ref>{{Cite web|url=https://discuss.kotlinlang.org/t/design-by-contract-dbc-design-considerations/1321|title=Design by Contract (DbC) design considerations|quote=Implement the full semantics of Eiffel DbC and improve upon it.|date=16 August 2012|website=Kotlin Discussions|language=en-US|access-date=4 April 2020|archive-date=5 April 2023|archive-url=https://web.archive.org/web/20230405081654/https://discuss.kotlinlang.org/t/design-by-contract-dbc-design-considerations/1321|url-status=live}}</ref> [[programming paradigm]].
 
Following [https://www.scala-js.org/ ScalaJS], Kotlin code may be [[Source-to-source compiler|transpiled]] to [[JavaScript]], allowing for interoperability between code written in the two languages. This can be used either to write full web applications in Kotlin, or to share code between a Kotlin backend and a JavaScript frontend.<ref>{{Cite web|title=Kotlin for JavaScript {{!}} Kotlin|url=https://kotlinlang.org/docs/js-overview.html#use-cases-for-kotlin-js|date=21 January 2021<!-- 11 February 2021 -->|access-date=2021-03-19|website=Kotlin Help|language=en-US|archive-date=14 July 2023|archive-url=https://web.archive.org/web/20230714143003/https://kotlinlang.org/docs/js-overview.html#use-cases-for-kotlin-js|url-status=live}}</ref>
Line 362:
}}
 
* {{mono|?:}} (the [[null coalescing operator]]) is a binary operator that returns the first operand, if non-null, else the second operand. It is often referred to as the [[Elvis operator]], due to its resemblance to an [[emoticon]] representation of Elvis Presley.
 
{{blockquote |
Line 411:
* [[IntelliJ IDEA]] has plug-in support for Kotlin.<ref>{{cite web |url=https://plugins.jetbrains.com/plugin/6954-kotlin |title=Kotlin :: JetBrains Plugin Repository |website=Plugins.jetbrains.com |date=31 March 2017 |access-date=11 April 2017 |archive-date=25 June 2023 |archive-url=https://web.archive.org/web/20230625051612/https://plugins.jetbrains.com/plugin/6954-kotlin |url-status=live}}</ref> IntelliJ IDEA 15 was the first version to bundle the Kotlin plugin in the IntelliJ Installer, and to provide Kotlin support out of the box.<ref>{{cite web |url=https://www.jetbrains.com/idea/whatsnew/ |title=What's New in IntelliJ IDEA 2017.1 |website=Jetbrains.com |access-date=11 April 2017 |archive-date=3 October 2023 |archive-url=https://web.archive.org/web/20231003212723/https://www.jetbrains.com/idea/whatsnew/ |url-status=live}}</ref>
* [[Gradle]]: Kotlin has seamless integration with Gradle, a [[build automation]] tool.<ref>{{Cite web |title=Gradle |url=https://kotlinlang.org/docs/gradle.html |access-date=2024-04-08 |website=Kotlin Help |language=en-US |archive-date=8 April 2024 |archive-url=https://web.archive.org/web/20240408064338/https://kotlinlang.org/docs/gradle.html |url-status=live}}</ref>
 
==Kotlin Multiplatform==
Kotlin Multiplatform allows a single [[codebase]] to target multiple platforms such as [[Microsoft Windows|Windows]], [[Linux]], web, Android and [[iOS]].<ref>{{Cite web |title=Kotlin Multiplatform Overview |url=https://developer.android.com/kotlin/multiplatform |access-date=2025-06-14 |website=Android Developers |language=en}}</ref><ref>{{Cite web |title=Kotlin Multiplatform – Build Cross-Platform Apps |url=https://www.jetbrains.com/kotlin-multiplatform/ |access-date=2025-06-14 |website=JetBrains |language=en}}</ref>
 
Compose Multiplatform is a multi-platform UI framework based on [[Jetpack Compose]]. It is Jetpack Compose for Android ported to Windows, [[macOS]], Linux, web, and iOS.<ref>{{Cite web |title=Compose Multiplatform – Beautiful UIs Everywhere |url=https://www.jetbrains.com/compose-multiplatform/ |access-date=2025-06-14 |website=JetBrains |language=en}}</ref><ref>{{Cite web |title=What's new in Compose Multiplatform 1.8.1 {{!}} Kotlin Multiplatform |url=https://www.jetbrains.com/help/kotlin-multiplatform-dev/whats-new-compose-180.html |access-date=2025-06-14 |website=Kotlin Multiplatform Help |language=en-US}}</ref><ref>{{Cite web |title=Compatibility and versions {{!}} Kotlin Multiplatform |url=https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-compatibility-and-versioning.html |access-date=2025-06-14 |website=Kotlin Multiplatform Help |language=en-US}}</ref> Jetpack Compose uses a Kotlin compiler plugin to transform composable functions into UI elements.<ref>{{Citation |last=Panjuta |first=Denis |title=Basic Jetpack Compose Elements |date=2023-12-12 |work=Tiny Android Projects Using Kotlin |pages=233–257 |url=https://doi.org/10.1201/9781032622538-9 |access-date=2025-06-14 |place=Boca Raton |publisher=Chapman and Hall/CRC |isbn=978-1-032-62253-8 |last2=Nwokike |first2=Loveth}}</ref> For example, the Text composable function displays a text label on the screen.
 
==Applications==
When Kotlin was announced as an official Android development language at [[Google I/O]] in May 2017, it became the third language fully supported for Android, after Java and C++.<ref>{{Cite news |last1=Lardinois|first1=Frederic |url=https://techcrunch.com/2017/05/17/google-makes-kotlin-a-first-class-language-for-writing-android-apps/ |title=Google makes Kotlin a first-class language for writing Android apps |website=techcrunch.com |language=en-US |date=17 May 2017 |access-date=28 June 2018 |url-status=live |archive-url=https://web.archive.org/web/20170522065631/https://techcrunch.com/2017/05/17/google-makes-kotlin-a-first-class-language-for-writing-android-apps/ |archive-date=22 May 2017}}</ref> {{As of|2020}}, Kotlin was the most widely used language on Android, with Google estimating that 70% of the top 1,000 apps on the Play Store were written in Kotlin. Google itself had 60 apps written in Kotlin, including Maps and Drive. Many Android apps, such as Google Home, were in the process of being migrated to Kotlin, and therefore use both Kotlin and Java. Kotlin on Android is seen as beneficial for its [[null-pointer safety]], as well as for its features that make for shorter, more readable code.<ref>{{cite web|url=https://www.zdnet.com/article/google-were-using-kotlin-programming-language-to-squash-the-bugs-that-cause-most-crashes/|website=ZDNet|title=Kotlin programming language: How Google is using it to squash the code bugs that cause most crashes|access-date=6 December 2020|archive-date=6 April 2023|archive-url=https://web.archive.org/web/20230406045458/https://www.zdnet.com/article/google-were-using-kotlin-programming-language-to-squash-the-bugs-that-cause-most-crashes/|url-status=live}}</ref>
 
InKtor additionis toJetbrains itsKotlin prominentfirst useframework onfor Android,building Kotlinserver wasand gainingclient tractionapplications.<ref>{{Citation in|title=ktorio/ktor server|date=2025-side06-16 development|url=https://github.com/ktorio/ktor |access-date=2025-06-16 |publisher=ktor.io}}</ref><ref>{{Cite web |title=Welcome {{!}} Ktor |url=https://ktor.io/docs/3.1.3/welcome.html |access-date=2025-06-16 |website=Ktor Help |language=en-US}}</ref> The [[Spring Framework]] officially added Kotlin support with version 5, on 4 January 2017.<ref>{{cite web |url=https://spring.io/blog/2017/01/04/introducing-kotlin-support-in-spring-framework-5-0 |website=Spring |title=Introducing Kotlin support in Spring Framework 5.0 |date=4 January 2017 |publisher=Pivotal |access-date=29 September 2020 |archive-date=23 August 2023 |archive-url=https://web.archive.org/web/20230823031409/https://spring.io/blog/2017/01/04/introducing-kotlin-support-in-spring-framework-5-0/ |url-status=live}}</ref> To further support Kotlin, Spring has translated all its documentation to Kotlin, and added built-in support for many Kotlin-specific features such as [[coroutines]].<ref>{{cite web|title=The State of Kotlin Support in Spring|url=https://blog.jetbrains.com/kotlin/2020/08/the-state-of-kotlin-support-in-spring/|website=JetBrains|date=14 August 2020|access-date=6 December 2020|language=en|archive-date=7 June 2023|archive-url=https://web.archive.org/web/20230607090327/https://blog.jetbrains.com/kotlin/2020/08/the-state-of-kotlin-support-in-spring/|url-status=live}}</ref> In addition to Spring, JetBrains has produced a Kotlin-first framework called Ktor for building web applications.<ref>{{cite web|url=https://dzone.com/articles/not-only-spring-boot-a-review-of-alternatives|website=DZone|title=Review of Microservices Frameworks: A Look at Spring Boot Alternatives|access-date=6 December 2020|archive-date=21 May 2023|archive-url=https://web.archive.org/web/20230521150446/https://dzone.com/articles/not-only-spring-boot-a-review-of-alternatives|url-status=live}}</ref>
 
In 2020, JetBrains found in a survey of developers who use Kotlin that 56% were using Kotlin for mobile apps, while 47% were using it for a web back-end. Just over a third of all Kotlin developers said that they were migrating to Kotlin from another language. Most Kotlin users were targeting Android (or otherwise on the JVM), with only 6% using Kotlin Native.<ref>{{cite web |title=Kotlin Programming - The State of Developer Ecosystem 2020 |url=https://www.jetbrains.com/lp/devecosystem-2020/kotlin/ |website=JetBrains |access-date=29 September 2020 |language=en |archive-date=5 April 2023 |archive-url=https://web.archive.org/web/20230405081654/https://www.jetbrains.com/lp/devecosystem-2020/kotlin/ |url-status=live}}</ref>
Line 451 ⟶ 456:
 
* [[Basecamp (software)|Basecamp]]<ref>{{Cite news |url=https://m.signalvnoise.com/how-we-made-basecamp-3s-android-app-100-kotlin-35e4e1c0ef12 |archive-url=https://wayback.archive-it.org/all/20180801160548/https://m.signalvnoise.com/how-we-made-basecamp-3s-android-app-100-kotlin-35e4e1c0ef12?gi=e9a4b3c9bf9f |url-status=dead |archive-date=1 August 2018 |title=How we made Basecamp 3's Android app 100% Kotlin – Signal v. Noise |date=29 April 2017 |work=Signal v. Noise |access-date=1 May 2017}}</ref>
* Corda, a distributed ledger developed by a consortium of well-known banks (such as [[Goldman Sachs]], [[Wells Fargo]], [[JPMorgan Chase|J.P. Morgan]], [[Deutsche Bank]], [[UBS]], [[HSBC]], [[BNP Paribas]], and [[Société Générale]]), has over 90% Kotlin code in its codebase.{{Citation needed|date=July 2025|reason=Making a big claim and naming a lot of names here, so where's the source?}}
* [[Coursera]]<ref>{{cite web |url=https://medium.com/coursera-engineering/becoming-bilingual-coursera-d8048dce73e3 |title=Becoming bilingual@coursera |date=26 April 2018 |access-date=24 July 2019 |archive-date=15 January 2023 |archive-url=https://web.archive.org/web/20230115223242/https://medium.com/coursera-engineering/becoming-bilingual-coursera-d8048dce73e3 |url-status=live}}</ref>
* DripStat<ref>{{cite web |url=https://blog.dripstat.com/kotlin-in-production-the-good-the-bad-and-the-ugly-2/ |title=Kotlin in Production – What works, Whats broken |website=Blog.dripstat.com |date=24 September 2016 |access-date=11 April 2017 |archive-date=1 July 2019 |archive-url=https://web.archive.org/web/20190701030659/https://blog.dripstat.com/kotlin-in-production-the-good-the-bad-and-the-ugly-2/ |url-status=dead}}</ref>