Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Getting Started with Kotlin for Android App Development - An Introduction and Basics

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 3
    • 0
    • 2.59k
    Comment on it

    As google’s Io 2k17 KOTLIN is announced as official language for android development. Hence, it is a time to gear up with this new language.

     

    So, today in this tutorial, I am going to show a simple android app demo in kotlin but before that let us first see the introduction of this Statically typed programming language.

     

     

     

     

    JetBrains presented this projecte named as kotlin in july 2011, The first release that was in February 15 after an year when jetbrains unveiled this project came as kotlin v1.0.

     

    Kotlin is a very similar language to swift, As soon as apple released swift programming language, Android developers were also willing to have some similar language.

     

    Kotlin is developed by JetBrains, it is statically-typed language. Syntax of kotlin is more concise and more expressive than java. It provides vast features like Lambda expressions, higher order functions, string templates and more. One of the most important point both kotlin and java can be used in single project.

     

    At the time of writing this blog android 3.0 is in canary channel yet there is time to come in stable.

     

     

     

     

    Follow these simple steps to get started with kotlin

     

    Requirements for creating kotlin project.

    • Android 3.0+
    • Android sdk

     

     

    Now, let us see the most efficient and concise way to adopt kotlin in your code.

    • Create a new project from your android studio 3.o+ it will automatically show kotlin support as checked, In case it is not checked mark it as checked.

     

     

    • Create an Activity and mark it checked for backward compatibility (in order to run on older android devices).

     

    And  that's all you have successfully created a new project in kotlin.

     

    Some basic things you need to follow in kotlin:

     

    For creating new instance of classes you need not to write new keyword before class name eg.

    new MyCustomClass()

     

    In kotlin

    MyCustomClass()

     

    For extending classes

     

    // In java 
    public class BaseActivity extends AppCompatActivity
    
    //In Kotlin
    class MainActivity : AppCompatActivity()
    

     

    Creating variables

    In java 
    Int a = 10;
    
    In Kotlin
    Var a = 10  // manage to typecast a variable automatically
    Or  
    Var a : int
    
    A = 10
    
    Val a =15 
    

     

    Creating functions

    In java 
    public void showToast(String message){
       Toast.makeText(this, message, Toast.LENGTH_LONG).show();
    }
    
    
    
    In kotlin
    fun showText(message : String){
       Toast.makeText(this, message, Toast.LENGTH_LONG).show()
    }
    

    So that’s all for now, follow me on findnerd for more tutorials and you can also checkout the following link for a working tutorial project on github.


    https://github.com/amitrai98/KotlinExample
     

    Happy coding :)

    Getting Started with Kotlin for Android App Development - An Introduction and Basics

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: