Build a simple calculator with TornadoFX

TornadoFX is a ui framework for Kotlin on top of JavaFX. It leverages the functional capabilities of Kotlin to create an easy to use ui framework with JavaFX as stable backbone. In this tutorial we will create a simple calculator that will allow us to add, subtract and multiply integers. Setting up For this tutorial we will use gradle with kotlin dsl to build the test application. mkdir kotlin_tornado cd kotlin_tornado gradle init --dsl kotlin The gradle build file is quiet extensive but I think the comments are explaining enough.
Read more...

Minimal Webservice with data classes and spring boot data rest

Spring Boot Data REST and Kotlin data classes enable an very code efficient way to provide CRUD Interfaces. We will create a small webservice for managing persons. Setting up For this tutorial we will use gradle with kotlin dsl to build the application. mkdir spring_data_class cd spring_data_class gradle init --dsl kotlin 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 plugins { kotlin("jvm") version "1.
Read more...

Part 2: Accessing the webservice with KTor client

In the last post Part 1 we created a simple webservice for organising tasks. This time we will access this service using the KTor client features. Setting up For this tutorial we will use gradle with kotlin dsl to build the application. mkdir kotlin_ktor_client cd kotlin_ktor_client gradle init --dsl kotlin plugins { application kotlin("jvm") version "1.3.0" } application { mainClassName = "client.ClientKt" } dependencies { compile(kotlin("stdlib")) compile("io.ktor:ktor-client-core:1.0.0") compile("io.ktor:ktor-client-apache:1.0.0") } repositories { mavenCentral() jcenter() } // We need this task to package the client into a jar task("packageClient", type = Jar::class) { from(configurations.
Read more...

Part 1: Building a simple web service with KTor

Ktor recently reached version 1.0.0 which motivated me to write this blog post. In this tutorial we will create a simple webservice for adding and listing tasks using the Kotlin framework Ktor. Ktor is a framework to build asynchronous server and client applications. Setting up For this tutorial we will use gradle with kotlin dsl to build the test application. mkdir kotlin_ktor cd kotlin_ktor gradle init --dsl kotlin plugins { application kotlin("jvm") version "1.
Read more...

Build Snake with Zircon and Kotlin Part 3

Previous tutorial: Part 2 At this part of the tutorial we want to create a real snake and let it eat some cherries. To archieve this we have to: Keep track of the snake tiles Add a cherry tile on a random position Check the cherry tile against the head of the snake and increment the snake length if they match Forming a tail The main change in this step is to update the GameController class.
Read more...

Simple Dependency Injection with Dagger 2

This tutorial will show you the most basic usage of the OpenSource google library Dagger 2. Dagger is a simple dependency injection framework that works completely at compile time eliminating all needs for reflection. The main use case for Dagger 2 is when you need dependency injection but dont want to use a giant application framework like Spring. It also provides an easy to use solution to implement dependecy injection in Android.
Read more...

Build Snake with Zircon and Kotlin Part 2

Previous tutorial: Part 1 At this part of the tutorial we want to make the square move on keyboard inputs. To archieve this we have to: add a listener for keyboard events move the square depending of the direction track the position of the snake and update it accordingly cleanup the old position Receiving input At first we need to define a direction interface. It contains the directions UP, DOWN, LEFT, RIGHT.
Read more...

Build Snake with Zircon and Kotlin Part 1

This tutorial will show you the basic usage of the OpenSource library Zircon. Setting up For this tutorial we will use gradle to build the application. But instead of groovy we will use the kotlin gradle dsl. mkdir kotlin_zircon cd kotlin_zircon gradle init --dsl kotlin All Scripts used in this tutorial are tested with PowerShell under Windows 10 but they should work fine in any posix compliant shell too.
Read more...