Introduction to Kotlin

In 2010, Jet Brains started working on a project called Project Kotlin. This aimed to develop a language that is easy, concise, and expressive. This is also a language that can help to improve productivity without compromising on quality, including that of backward compatibility and interoperability with existing code bases. Other than freedom from semicolons, there are a number of reasons to use Kotlin.

For a start, a beginner programmer can feel as comfortable as an experienced developer when using it. It also compiles to Java-6 bytecode, which allows a developer to use advanced features such as lambda expressions with legacy code. Kotlin is 100% interoperable with Java, so it is possible to call Kotlin code in Java as well as calling Java code in Kotlin. Furthermore, it is concise and expressive, and it helps avoid the boilerplate code that is required in Java. Kotlin is safe, therefore most Null Pointer Exceptions (NPEs) can be avoided. By default, it is not allowed to assign null values to variables. If the type of the variable is verified at compile time, the language is considered to be statically typed. Kotlin is a statically typed language and the benefit of this is that all tricky and trivial bugs can be caught at an early stage. With dynamically typed languages, type checking is performed at runtime. Perl, Smalltalk, and Ruby belong to a dynamically typed language group. Kotlin has great tooling support because it is a product of Jet Brains, a company renowned for providing IDEs for development. In addition, Kotlin supports Android because it is officially supported by Google. Kotlin supports Kotlin/Native technology for compiling Kotlin code in native binaries which does not rely on virtual machine and Kotlin supports browsers because all modern languages should work with JavaScript. A number of big brands (including Pinterest, Uber, Gradle, and Evernote) have started using Kotlin as a main language, and they feel that it helps to improve their productivity and quality of code. 

With the help of Kotlin, we will now create our first hello world application as follows: 

  1. Start IntelliJ IDE and click on File.
  2. Click on the New option and then click on the Project in the Menu
  3. From the left pane in the newly opened window, select Kotlin | Kotlin/JVM and then press Next.
  4. Assign a project name and location, making sure that the latest SDK is selected.
  1. Click on FinishIntelliJ IDE will open a new window with preconfigured files and folders. src is a source folder where all Kotlin files will be added.
  2. Right-click on src and select New. Under this, click on Kotlin File/Class.
  3. Assign a name, select a file from the Kind menu, and press OK.
  4. Add the following code in the newly opened window:
fun main(args: Array<String>) {
println("Hello world")
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.218.69