Slide 1

Slide 1 text

@charlesmuchene Working with Java & Kotlin

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

Compilation + Execution Sources Bytecode JVM Application

Slide 5

Slide 5 text

Execution Bytecode JVM Application

Slide 6

Slide 6 text

JVM Kotlin Java

Slide 7

Slide 7 text

Why Kotlin? Concise Safe Interoperable Tooling

Slide 8

Slide 8 text

Kotlin Android JVM Web Native

Slide 9

Slide 9 text

Kotlin Android JVM Web Native

Slide 10

Slide 10 text

Code demo

Slide 11

Slide 11 text

Kotlin + Spring

Slide 12

Slide 12 text

Person RESTful API

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

Running Spring Boot App

Slide 17

Slide 17 text

App demo

Slide 18

Slide 18 text

Kotlin + Android

Slide 19

Slide 19 text

Countries App

Slide 20

Slide 20 text

Countries App Flow Launch Fetch online Display

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

App demo

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

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

Slide 30

Slide 30 text

charlesmuchene