Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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

Charles Muchene

March 02, 2019
Tweet

More Decks by Charles Muchene

Other Decks in Technology

Transcript

  1. @charlesmuchene
    Working with Java & Kotlin

    View Slide

  2. Agenda
    • What is Kotlin?
    • Kotlin - Java interoperability
    • Kotlin on Spring
    • Kotlin on Android

    View Slide

  3. Compilation
    Java Source Java Compiler Java Bytecode
    Student.java Student.class

    View Slide

  4. Compilation + Execution
    Sources
    Bytecode
    JVM
    Application

    View Slide

  5. Execution
    Bytecode JVM Application

    View Slide

  6. JVM
    Kotlin
    Java

    View Slide

  7. Why Kotlin?
    Concise Safe Interoperable Tooling

    View Slide

  8. Kotlin
    Android
    JVM Web Native

    View Slide

  9. Kotlin
    Android
    JVM
    Web Native

    View Slide

  10. Code demo

    View Slide

  11. Kotlin + Spring

    View Slide

  12. Person RESTful API

    View Slide

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

    View Slide

  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)
    }

    View Slide

  15. Person Class
    @Entity
    data class Person(@Id val id: Long, val firstName: String, ...

    View Slide

  16. Running Spring Boot App

    View Slide

  17. App demo

    View Slide

  18. Kotlin + Android

    View Slide

  19. Countries App

    View Slide

  20. Countries App Flow
    Launch Fetch online Display

    View Slide

  21. View Slide

  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)
    ...
    }
    ...

    View Slide

  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()
    }
    }

    View Slide

  24. Country Class
    @Parcelize
    data class Country(val name: String, val capital: String, ...

    View Slide

  25. App demo

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  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

    View Slide

  30. charlesmuchene

    View Slide