Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; SEOFriendlyImages has a deprecated constructor in /home/tutorig3/public_html/wp-content/plugins/seo-image/seo-friendly-images.class.php on line 2

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /home/tutorig3/public_html/wp-content/themes/mts_interactive/options/php-po/php-po.php on line 185
Kotlin Tutorial | Introduction to Kotlin Programming language - Tutorialwing

Kotlin Tutorial | Introduction to Kotlin Programming language

We have recently published 100+ articles on android tutorials with kotlin and java. If you need, you may visit Android Tutorial for beginners page. You can also check Kotlin Tutorial for beginners. Also, if you are interested in content writing, you can mail us at
In Google I/O 2017, Kotlin programming language was announced as an official programming language for android application development. With this announcement, Demand for kotlin programming language has increased significantly. So, here, we are presenting you tutorials on Kotlin programming language.

This is my first tutorial on Kotlin programming language. In this post, i will be covering introduction of this programming language.

Kotlin is statically typed programming language for modern multi-platform applications. It is developed by JetBrains. You can develop application for JVM, android and web browser using this language. It’s syntax is more expressive and concise than that of Java. However, Kotlin and Java is interoperable i.e. you can use both language in same application.

Many of you might be thinking why are we using kotlin? Please go through the features of Kotlin programming language to get your answer.

Major features of Kotlin Programming language –

a. Concise
b. Safe
c. Interoperable
d. Tool-friendly

Now, we will go through each feature one by one

1. Concise

As you know very well, Bugs in your code is directly proportional to the total number of lines of code it has. Means, more the number of lines of code, more chances of having bugs in the code. Kotlin language needs just a few lines of code to do the job. It drastically reduces the amount of boilerplate code. For example,

We are just comparing between java and kotlin language. Our job is to create a simple class that contains getters and setters as well as overriding methods equals(), hashCode() and toString(). Let’s see how we can achieve it using both languages

public class Customer {
   private String name;
   private String email;
   private String company;

   public Customer(String name) {
       this(name, "", "");

   public Customer(String name, String email) {
       this(name, email, "");


   public Customer(String name, String email, String company) { = name; = email; = company;

   public String getName() {
       return name;

   public void setName(String name) { = name;

   public String getEmail() {
       return email;

   public void setEmail(String email) { = email;

   public String getCompany() {
       return company;

   public void setCompany(String company) { = company;

   public boolean equals(Object o) {
       if (this == o) return true;
       if (o == null || getClass() != o.getClass()) return false;

       Customer customer = (Customer) o;

       if (name != null ? !name.equals( : != null) return false;
       if (email != null ? !email.equals( : != null) return false;
       return company != null ? company.equals( : == null;

   public int hashCode() {
       int result = name != null ? name.hashCode() : 0;
       result = 31 * result + (email != null ? email.hashCode() : 0);
       result = 31 * result + (company != null ? company.hashCode() : 0);
       return result;

   public String toString() {
       return "Customer{" +
               "name='" + name + '\'' +
               ", email='" + email + '\'' +
               ", company='" + company + '\'' +
data class Customer(var name: String, var email: String = "", var company: String = "")

As you can see yourself, There is a huge difference in number of lines of code between kotlin and java programming language to perform the same task. Single line in Kotlin is equivalent to entire class written in java. You will observe this difference many times if you are using Kotlin.

2. Safe

This language avoids entire classes of errors such as null pointer exceptions, the billion dollar mistakes. Let’s take an example –
There are 2 variables in the method. One can be null but other must not be null. Let’s see the example in both language

String neverNull = "something";
String mayBeNull = null;
if (neverNull.length > 0) {   // This is OK...
   // write something here...

if (mightBeNull.length > 0) { // This is OK...
   // write something here...
var neverNull: String = "something"
var mightBeNull: String? = null // "?" indicates this can be null

if (neverNull.length > 0) {   // This is OK
   // write something here...

if (mightBeNull.length > 0) { // Compiler catches this error for you
   // write something here...

As you can see clearly, The Kotlin compiler enforces that variables that can hold null values are explicitly declared – thus no more NullPointerExceptions at runtime! You must declare explicitly if a value may be null.

3. Interoperable

Java and Kotlin are 100% compatible. You can also use any existing library on the JVM, including SAM support. You can use both languages in the same project. You can convert java code into Kotlin and vice-versa. You just need to target either JVM or Javascript. Write code in Kotlin and decide where you want to go. For example,

Both code has meaning.

Button button = (Button) findViewById(; 
button.setOnClickListener(new View.OnClickListener() { 
 public void onClick(View view) {
 /* your code */
val button = findViewById( as Button 
button.setOnClickListener { view -> /* your code */}

4. Tool-Friendly

You can use any Java IDE to do programming in Kotlin. You can use IntelliJ, Android Studio or Eclipse etc. to develop application using Kotlin. You can also use command line to build application using Kotlin. You can use any way to code using Kotlin.

Start With Android Studio
Android Studio
Bundled with Studio 3.0, plugin available for earlier versions
Start with Eclipse
Install the plugin from the Eclipse Marketplace
Start With IntelliJ
Bundled with Community Edition or IntelliJ IDEA Ultimate
Start with Command line
Command Line
Use any editor and build from the command line

Support Us

If you like Tutorialwing and would like to contribute, you can email an article on any educational topic at We would love to publish your article. See your article on Tutorialwing and help others with your knowledge. Follow Facebook, LinkedIn, Google+, Twitter, Youtube for latest updates.
We have recently published 100+ articles on android tutorials with kotlin and java. If you need, you may visit Android Tutorial for beginners page. You can also check Kotlin Tutorial for beginners