KOTLIN - The Next Programming Language.



Kotlin is a statically-typed programming language that runs on the Java virtual machine and also can be compiled to JavaScript source code or uses the LLVM compiler infrastructure. Its primary development is from a team of JetBrains programmers based in Saint Petersburg, Russia. While the syntax is not compatible with Java, Kotlin is designed to interoperate with Java code and is reliant on Java code from the existing Java Class Library, such as the collections framework.

The name comes from Kotlin Island, near St. Petersburg. Andrey Breslav mentioned that the team decided to name it after an island just like Java was named after the Indonesian island of Java.

Kotlin is a fully supported programming language on Android.

Simplest Version

Object Oriented "Hello"

Android Activity


History

In July 2011 JetBrains unveiled Project Kotlin, a new language for the JVM, which had been under development for a year. JetBrains lead Dmitry Jemerov said that most languages did not have the features they were looking for, with the exception of Scala. However, he cited the slow compile time of Scala as an obvious deficiency. One of the stated goals of Kotlin is to compile as quickly as Java. In February 2012, JetBrains open sourced the project under the Apache 2 license.

JetBrains hopes that the new language will drive IntelliJ IDEA sales.

Kotlin v1.0 was released on February 15, 2016. This is considered to be the first officially stable release and JetBrains has committed to long-term backwards compatibility starting with this version.

At Google I/O 2017, Google announced first-class support for Kotlin on Android.

Philosophy


Development lead Andrey Breslav has said that Kotlin is designed to be an industrial-strength object-oriented language, and a "better language" than Java, but still be fully interoperable with Java code, allowing companies to make a gradual migration from Java to Kotlin.

Syntax

Kotlin variable declarations and parameter lists have the data type come after the variable name (and with a colon separator), similar to Pascal. As in Scala and Groovy, semicolons are optional as a statement terminator; in most cases a newline is sufficient for the compiler to deduce that the statement has ended.

Semantics

In addition to the classes and methods (called member functions in Kotlin) of object-oriented programming, Kotlin also supports procedural programming with the use of functions. As in C and C++, the entry point to a Kotlin program is a function named "main", which is passed an array containing any command line arguments. Perl and Unix/Linux shell script-style string interpolation is supported. Type inference is also supported.

Hello, world! example


Kotlin makes a distinction between nullable and non-nullable data types. All nullable objects must be declared with a "?" postfix after the type name. Operations on nullable objects need special care from developers: null-check must be performed before using the value. Kotlin provides null-safe operators to help developers:
  • ?. (safe navigation operator) can be used to safely access a method or property of a possibly null object. If the object is null, the method will not be called and the expression evaluates to null.
  • ?: (null coalescing operator) often referred to as the Elvis operator:

An example of the use of the safe navigation operator:


Tools
  • IntelliJ IDEA has plug-in support for Kotlin. IntelliJ IDEA 15 is the first version to bundle Kotlin plugin in the IntelliJ Installer, and provide support of it out of the box.
  • JetBrains also provides a plugin for Eclipse.
  • Integration with common Java build tools is supported including Apache Maven, Apache Ant, and Gradle.

Applications

One of the obvious applications of Kotlin is Android development. The platform was stuck on Java 7 for a while (with some contemporary language features made accessible through the use of Retrolambda or the Jack toolchain) and Kotlin introduces many improvements for programmers such as null-pointer safety, extension functions and infix notation. Accompanied by full Java compatibility and good IDE support (Android Studio) it is intended to improve code readability, give an easier way to extend Android SDK classes and speed up development.
Kotlin was announced as an official Android development language at Google I/O 2017. It became the third language fully supported for Android, in addition to Java and C++.

Adoption

According to the Kotlin website, Prezi is using Kotlin in the backend. DripStat has done a writeup of their experience with Kotlin.
According to Jetbrains blog, Kotlin is used by Amazon Web Services, Pinterest, Coursera, Netflix, Uber, Square, Trello, Basecamp, and others. Corda, a distributed ledger developed by a consortium of well-known banks (such as Goldman Sachs, Wells Fargo, J.P. Morgan, Deutsche Bank, UBS, HSBC, BNP Paribas, Société Générale), has over 90% Kotlin in its codebase.
According to Google, Kotlin has already been adopted by several major developers—Expedia, Flipboard, Pinterest, Square, and others—for their Android production apps.


Build environment requirements

In order to build Kotlin distribution you need to have:
  • Apache Ant 1.9.4 and higher
  • JDK 1.6, 1.7 and 1.8
  • Setup environment variables as following:

For local development, if you're not working on bytecode generation or the standard library, it's OK to have only JDK 8 installed, and to point all of the environment variables mentioned above to your JDK 8 installation.

Building

To build this project, first time you try to build you need to run this:


which will setup the dependencies on
  • intellij-core is a part of command line compiler and contains only necessary APIs.
  • idea-full is a full blown IntelliJ IDEA Community Edition to be used in the plugin module.
Then, you may run Gradle to build the project and run tests, using:


command on Unix/macOS, or


on Windows.

Important gradle tasks
  • clean- clean build results
  • dist - assembles the compiler distribution into dist/kotlinc/ folder
  • ideaPlugin - assembles the Kotlin IDEA plugin distribution into dist/artifacts/Kotlin folder
  • install - build and install all public artifacts into local maven repository
  • runIde - build IDEA plugin and run IDEA with it
  • coreLibsTest - build and run stdlib, reflect and kotlin-test tests
  • gradlePluginsTest - build and run gradle plugin tests
  • compilerTest - build and run all compiler tests
  • ideaPluginTest - build and run all IDEA plugin tests

Working with the project in IntelliJ IDEA

Working with the Kotlin project requires IntelliJ IDEA 2017.3. You can download an Early Access Preview version of IntelliJ IDEA 2017.3 here.

To import the project in Intellij choose project directory in Open project dialog. Then, after project opened, Select File -> New... -> Module from Existing Sources in the menu and select build.gradle.kts file in the project's root folder.

In the import dialog, select use default gradle wrapper .

To be able to run tests from IntelliJ easily, Delegate IDE build/run actions to Gradle in the Gradle runner settings.

At this time, you can use the latest released 1.1.x version of the Kotlin plugin for working with the code. To make sure you have the latest version installed, use Tools | Kotlin | Configure Kotlin Plugin Updates and press "Check for updates now".

Compiling and running


From this root project there are Run/Debug Configurations for running IDEA or the Compiler Tests for example; so if you want to try out the latest and greatest IDEA plugin

  • VCS -> Git -> Pull
  • Run the "IDEA" run configuration in the project
  • a child IntelliJ IDEA with the Kotlin plugin will then startup
Contributing

We love contributions! There's lots to do on Kotlin and on the standard library so why not chat with us about what you're interested in doing? Please join the #kontributors channel in our Slack chat and let us know about your plans.

If you want to find some issues to start off with, try this query which should find all Kotlin issues that marked as "up-for-grabs".

Currently only committers can assign issues to themselves so just add a comment if you're starting work on it.

A nice gentle way to contribute would be to review the standard library docs and find classes or functions which are not documented very well and submit a patch.

In particular it'd be great if all functions included a nice example of how to use it such as for the hashMapOf() function. This is implemented using the @sample macro to include code from a test function. The benefits of this approach are twofold; First, the API's documentation is improved via beneficial examples that help new users and second, the code coverage is increased.

Also the JavaScript translation could really use your help. See the JavaScript contribution section for more details.

Some of the code in the standard library is created by generating code from templates. See the README in the stdlib section for how run the code generator. The existing templates can be used as examples for creating new ones.

Running specific generated tests


If you need to debug a specific generated test, ensure that you have the Working directory in your IntelliJ run configuration set to the root directory of this project. If you don't, every test you try to run will fail with a No such file or directory exception.

Submitting patches


The best way to submit a patch is to fork the project on github then send us a pull request via github.

If you create your own fork, it might help to enable rebase by default when you pull by executing



This will avoid your local repo having too many merge commits which will help keep your pull request simple and easy to apply.

Some handy links:

This is not the just the beginning of the Kotlin Series. As on the nest Post you will get the knowledge about -  Why you should totally switch to Kotlin. So Stay Tuned for tomorrow's post.
.


Comments

Popular posts from this blog

The Principle About Bluetooth 5.0 - Explained

India, The Apparent Land Of kamasutra - Becomes The hird-highest visitors of Porn Hub

Google Tez, Digital Payment App 'Made for India' - Everything You Should Know Before Using It.

Technical News - A Leap Ahead.