in July 2011 as a new programming language for the JVM. In February 2012, Jetbrains open sourced the project under the Apache 2 license. The main goal of the project was to write Jetbrains products like IntelliJ IDEA. The first stable version was released in February 2016. During Google I/O 2017, Google announced the support for Kotlin on Android. Since then, Kotlin has been the official recommended language for Android development. What is Kotlin?
Android development, backend development powered by Ktor and multiplaform development (JVM, Javascript, Native). Kotlin also has a great community, counting +30k stars on main Github repository, +30k members on official Slack and +50k questions on Stackoverflow. In 2018, Stackoverflow published a survey that introduced Kotlin at the second position about the most loved programming languages. Kotlin ecosystem and community
projects, such as Evernote, Coursera and Atlassian. And here at Brazil, we have a lot of companies using Kotlin, such as Aegro, Creditas, C6 Bank, Hash Payments, Itaú and so on. And a lot of popular open source projects are adding support for Kotlin, such as Gradle and Spring. Kotlin adoption
main() { val greeting: String = "Developer Student Club" println("Hello, " + greeting) } * In Kotlin, the args parameter in main function isn’t mandatory.
val greeting: String = "Developer Student Club" println("Hello, $greeting”) } In terms of syntax, there is a notable difference, since using templates, you compose the string in a more fashion way. In terms of runtime, there is no big difference, since the Kotlin compiler produces the same code for both string concatenation using + operator and string templates.
= 25 age = 20 !// it produces a compiler error because val properties cannot be reassigned Immutable states are a good way to keep a consistent state during program execution. If you want a new value, you need to produce a new state instead of changing the current one.
Person(var username: String, var age: Int) Data classes are a good way to represent some kind of data in your program with less boilerplate. By default, data classes implements equals(), hashCode() and toString() functions.
{ private val brazilianDateFormat = SimpleDateFormat("dd/MM/yyyy") private val unitedStatesDateFormat = SimpleDateFormat("mm-dd-yyyy") fun createDateInBrazilianFormat(value: String): Date { return brazilianDateFormat.parse(value) } fun createDateInUnitedStatesFormat(value: String): Date { return unitedStatesDateFormat.parse(value) } } fun main() { DateUtils.createDateInBrazilianFormat("16/01/2021") DateUtils.createDateInBrazilianFormat("01-16-2021") }
code class PersonKotlin { var name: String = "" var age: Int = 0 } !// Java code public class MainJava { public static void main(String[] args) { PersonKotlin personKotlin = new PersonKotlin(); personKotlin.setName("Wellington"); personKotlin.setAge(25); System.out.println(personKotlin.getName()); System.out.println(personKotlin.getAge()); } }