Working with Java & Kotlin

Working with Java & Kotlin

The presentation shows how Kotlin fits in the Java Ecosystem while demonstrating some basic language features using sample code: console, spring boot and android app

8e46b74e930fdddb93a58e990f0a47b2?s=128

Charles Muchene

March 02, 2019
Tweet

Transcript

  1. @charlesmuchene Working with Java & Kotlin

  2. Agenda • What is Kotlin? • Kotlin - Java interoperability

    • Kotlin on Spring • Kotlin on Android
  3. Compilation Java Source Java Compiler Java Bytecode Student.java Student.class

  4. Compilation + Execution Sources Bytecode JVM Application

  5. Execution Bytecode JVM Application

  6. JVM Kotlin Java

  7. Why Kotlin? Concise Safe Interoperable Tooling

  8. Kotlin Android JVM Web Native

  9. Kotlin Android JVM Web Native

  10. Code demo

  11. Kotlin + Spring

  12. Person RESTful API

  13. Application File @SpringBootApplication class Application fun main(args: Array<String>) { runApplication<Application>(*args)

    }
  14. Person Controller @RestController class PersonController(private val personRepository: PersonRepository) { @GetMapping("/person")

    fun readAll() = personRepository.findAll() @GetMapping("/person/{id}") fun readOne(@PathVariable id: Long) = personRepository.findById(id) }
  15. Person Class @Entity data class Person(@Id val id: Long, val

    firstName: String, ...
  16. Running Spring Boot App

  17. App demo

  18. Kotlin + Android

  19. Countries App

  20. Countries App Flow Launch Fetch online Display

  21. None
  22. Main Activity class MainActivity : AppCompatActivity() { private lateinit var

    viewModel: CountryViewModel private var countryAdapter = CountryAdapter() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) ... } ...
  23. Country Details ViewModel class CountryDetailsViewModel : ViewModel() { fun getDetails(country:

    Country): String = with(country) { """ Native Name: $nativeName Demonym: ${demonym.orDash} Population: ${String.format("%,d", population)} Language(s): ${languages.joinToString(transform = Language::toString)} Currency: ${currencies.joinToString(transform = Currency::toString)} Timezone(s): ${timezones.joinToString()} """.trimIndent() } }
  24. Country Class @Parcelize data class Country(val name: String, val capital:

    String, ...
  25. App demo

  26. Kotlin Love - StackOverflow https://insights.stackoverflow.com/survey/2018/#technology

  27. Kotlin Interest - StackOverflow https://insights.stackoverflow.com/survey/2018/#technology

  28. Kotlin Interest - Hackerrank https://research.hackerrank.com/developer-skills/2019

  29. Resources • https://kotlinlang.org/ • https://insights.stackoverflow.com/survey/2018 • https://research.hackerrank.com/developer-skills/2019 • https://github.com/charlesmuchene/learn-kotlin-app •

    https://github.com/charlesmuchene/learn-kotlin-jvm • https://github.com/charlesmuchene/learn-kotlin-spring-boot
  30. charlesmuchene