Kotlin: A Beginner’s Guide to Modern Android Development

 

Kotlin :

Hello World is the first thing we practice in every programming language we initially begin with the same scenario we implement in Kotlin as well.

You might have heard by now or its good to know that Kotlin is a official language for android developers.

We generally make use of programming languages to write a piece of code to do a task and some times we need to use them throughout the app.Yes you are right its called a method.

Going forward yes Kotlin do have these methods which are implemented just like in java. But oh they are not methods then what they might be ?

 

How to declare a Method in Kotlin ?

There are methods in Kotlin too but they are not called as methods but are functions  shortly as “fun”. Ya its even fun in using them –> just a joke.

And declaring this very simple when compared to that of java version of methods. Not sure let’s get through

 

Let’s have a look how we implemented in java

java:

public void welcome(){}

Its a public method with no return type if need more information ping me in comment section below.

 

Now we will see how to create a similar method in Kotlin of course with same name.

Kotlin:

fun welcome(){}

This does the same functionality as of the above statement but you can see there is no void specified and public i.e, access specifiers yep Kotlin does it for you really don’t believe ping me down in comment section for more info with a tutorial.

How to Print a Statement in Kotlin?

As we said coding is fun with Kotlin now you will notice it too.Generally we might have came across sout. What is sout? try to type in android studio only applicable inside a method and let me know.

 

java:

Ya sout stands for System.out.println.Which we generally use in java to print output or any statement so that user can read and proceed further.

System.out.println("");

 

Kotlin:

print("Welcome to kotlin!!!")

Yes that’s it nothing is missing rest every thing Kotlin takes care for you need not worry.Don’t trust me read till the end of the tutorial you will get the answer.

 

How to declare main method i.e, fun in Kotlin?

Again there is a difference in declaration of main method.And if you don’t know what is main method or function its the first method by which program execution will start till you declare a main method and make use of it by calling you method from there nothing will get executed.

 

java:

public static void main(String[] args){}

and now

 

Kotlin:

fun main(args : Array<String>){}

 

here in the main method we will call our statement declared method

 

fun welcome(){

    print("Welcome to kotlin!!!")

}


fun main(args : Array<String>){

    welcome()

}

 

And now we can run the program please do watch attached youtube tutorial for more info on how to run a program in Kotlin.

 

Note:

Now as Kotlin is the official language so no need of java is the question? …java is important though we use Kotlin because every line of code you write will get converted into java and class file is generated as required.

If you have any query in the Introduction kotlin tutorial do let us know in the comment section below.

 

 

 

Show Buttons
Hide Buttons
Read previous post:
Android IOS Hello word flutter | Programming with flutter

  Flutter : Hello welcome to the new flutter programming. Every beginning of learning a new language is with a...

Close