Book Image

Kotlin Programming By Example

By : Iyanu Adelekan
Book Image

Kotlin Programming By Example

By: Iyanu Adelekan

Overview of this book

Kotlin greatly reduces the verbosity of source code. With Google having announced their support for Kotlin as a first-class language for writing Android apps, now's the time learn how to create apps from scratch with Kotlin Kotlin Programming By Example takes you through the building blocks of Kotlin, such as functions and classes. You’ll explore various features of Kotlin by building three applications of varying complexity. For a quick start to Android development, we look at building a classic game, Tetris, and elaborate on object-oriented programming in Kotlin. Our next application will be a messenger app, a level up in terms of complexity. Before moving onto the third app, we take a look at data persistent methods, helping us learn about the storage and retrieval of useful applications. Our final app is a place reviewer: a web application that will make use of the Google Maps API and Place Picker. By the end of this book, you will have gained experience of of creating and deploying Android applications using Kotlin.
Table of Contents (12 chapters)

Fundamentals of the web

Most applications communicate with a server in one way or another. It is imperative that you understand a number of concepts related to the web before continuing in this book. This section explains those concepts concisely.

What is the web?

The web is a complex system of interconnected systems possessing the ability to communicate with other systems existing on a common network via one or more protocols. A protocol is an official, well-defined system of rules governing the exchange of information between devices.

Hypertext Transfer Protocol

All communications over the web are made in accordance with a protocol. A particularly important protocol for fostering communication between systems is the Hypertext Transfer Protocol (HTTP).

Billions of images, videos, text files, documents, and other files are transferred across the internet on a daily basis. These files are all transferred through HTTP. HTTP is an application protocol for distributed and hypermedia information systems. It can be said to be a foundational component for communication across the internet. A major benefit of using HTTP for data transfer across systems is that it is highly reliable. This is as a result of its utilization of reliable protocols, such as the Transmission Control Protocol (TCP) and Internet Protocol (IP).

Clients and servers

A web client is any application that communicates with a web server utilizing HTTP. A web server is a computer that provides – or serves – web resources to web clients. A web resource is anything that provides web content. A web resource can be a media file, an HTML document, a gateway, and so on. Clients need web content for various purposes, such as information rendering and data manipulation.

Clients and servers communicate with each other via HTTP. One major reason for the utilization of HTTP is the fact that it is extremely reliable in data transmission. The use of HTTP ensures data loss does not occur in a request-response cycle.

HTTP requests and responses

An HTTP request – as the name replies is a solicitation for a web resource sent by a web client to a server over HTTP. An HTTP response is a reply sent by a server to a request in an HTTP transaction:

HTTP methods

HTTP supports a number of request methods. These methods can also be referred to as commands. HTTP methods specify the type of action to be performed by the server. Some common HTTP methods are tabularized as follows:

HTTP method Description

GET

Retrieves a named resource present on the client.

POST

Sends data from a client to a server.

DELETE

Deletes a named resource residing on a server.

PUT

Store data collected by the client in a named resource residing on the server.

OPTIONS

Returns HTTP methods that the server supports.

HEAD

Retrieves HTTP headers with no content.