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

Functional Kotlin starting from Java

This post is about the transition from Kotlin sourcecode that looks like java code to code that uses the functional Kotlin constructs. Starting up I will write about a completely made up class here but I experienced that you can do that with almost any class in the entire codebase. Inspiration from the daily programmer: word funnel Starting with Java We start with the java implementation of the word funnel puzzle mentioned above
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...

Null pointer in Kotlin

The Null Pointer Problem Java devs have struggled withe the Problem of the NullPointerException for years and more years to come. It has been named the ‘Billion Dollar Mistake’ and it probably did cost something ranging in this number. Kotlin is coming up with a pretty neat solutions to this old Problem. It does not prevent NullPonterExceptions completely but it warns you every time you are about to introduce code that could lend to this technical debt.
Read more...