Book Image

Kotlin Blueprints

By : Ashish Belagali, Akshay Chordiya, Hardik Trivedi
Book Image

Kotlin Blueprints

By: Ashish Belagali, Akshay Chordiya, Hardik Trivedi

Overview of this book

Kotlin is a powerful language that has applications in a wide variety of fields. It is a concise, safe, interoperable, and tool-friendly language. The Android team has also announced first-class support for Kotlin, which is an added boost to the language. Kotlin’s growth is fueled through carefully designed business and technology benefits. The collection of projects demonstrates the versatility of the language and enables you to build standalone applications on your own. You’ll build comprehensive applications using the various features of Kotlin. Scale, performance, and high availability lie at the heart of the projects, and the lessons learned throughout this book. You’ll learn how to build a social media aggregator app that will help you efficiently track various feeds, develop a geospatial webservice with Kotlin and Spring Boot, build responsive web applications with Kotlin, build a REST API for a news feed reader, and build a server-side chat application with Kotlin. It also covers the various libraries and frameworks used in the projects. Through the course of building applications, you’ll not only get to grips with the various features of Kotlin, but you’ll also discover how to design and prototype professional-grade applications.
Table of Contents (16 chapters)
Title Page
About the Authors
About the Reviewer
Customer Feedback

Building our app

We will be building a command-line based CSV reader that prints the unique entries of the columns and their counts, based on user input in Kotlin Native.

Writing the main function

Kotlin Native has the same language syntax and includes the standard library. Hence, the main function in Kotlin Native looks the same as the main function in JVM or JS. It is similar to the following syntax:

    // Starting point
    fun main(args: Array<String>) {
      // Rest of code over here..

The main function takes args, which contains the arguments from the command line.

Reading command-line arguments

We will be taking two arguments from the command line:

  • The name of the CSV file to read
  • The column number to find unique entries from

The following code block shows how to read arguments passed from the command line:

    // Get command line input
    if (args.size != 2) {
      println("Usage: csv_filename column_number")
    val fileName = args[0]
    val columnNumber...