Hello World in Kotlin

      No Comments on Hello World in Kotlin

Hello World – Most of you know the first sample application used in most programming languages and most platforms. Creating Hello World in Kotlin for Android will show us how easy it is to create your Kotlin apps.

1. Android Studio installation

In order to create an Android app at all, we need to have a development environment in which the application can be programmed.
One of the most used (and directly supported and developed by Google) is Android Studio. This IDE (Integrated Development Environment) is derived from IDE Idea developed by JetBrains (which is, among other things, the creator of Kotlin).
Android Studio is available for both Windows and Linux and Mac.

Note: Android Studio is constantly evolving. The latest version, including installation instructions, can be found at developer.android.com/studio.
Kotlin is supported by version 3.0 Android by default, older plug-ins have to install plug-in for Kotlin.

JDK (Java Development Kit) installation

Android Studio as such needs JDK (Java Development Kit). If you encounter an error message about a missing JDK when installing, you can download it to Oracle Java SE Downloads. You need to select version 8 or higher, and before you download it, you need to confirm the License Agreement on that page.

Android Studio installation

Installing Android Studio as such is quite simple for a normal user, but if you need to get started with the installation, you can find it on the Install Android Studio page.

2. Create the first project

Our first project will be Hello World. It only shows when Hello World – nothing more, nothing less.

Create a new project

  1. On the Android Studio Startup screen, select Start and new Android Studio project
  1. In the next window, select the project type – Phone and Tablet and leave empty activity. Click Next to continue.
  1. In the next window, enter a project name (such as HelloWorld) and select Kotlin as the language. Like the Minimum API Level, you can either have the default value offered by Android Studio, or choose one of the “newer” APIs (6.0 or higher). Then complete the project wizard with the Finish button.
  1. Once the project wizard finishes, the Android Studio itself will open. The project as such will start indexing, synchronizing, and assembling (“building”).
  1. Indexing, syncing, and build (“build”) takes a while, but once it is finished, it is possible to run the application. Use a triangle icon – see screen
  1. In order for an application to run somewhere, it is necessary to have either a physically connected Android phone or virtual devices (sometimes referred to as emulators). In this case, the emulator will most likely be used. After installing Android Studio, one or two devices will be created already, so choose one.
  1. Then, when the build is rebuilt and then the APK is prepared and uploaded to the emulator (or a physically existing connected phone), the application starts. Result – see screen.

Note: When creating this article, the Android Studio 3.3 Beta 4 version was used.

That’s all, next time we start with the teachings of Kotlin.