Learning Kotlin in 2022

In this article I’ll teach you the core of the kotlin programming language, kotlin is a general-purpose statically typed language that has become extremely popular in the last few years. kotlin can be used on both the client and the server which means the code can be run either on the user’s device the client or on some computer in the cloud called the server which responds to requests from the client on the client kotlin is now widely used for android development to write apps for the 2.5 billion devices running the Android operating system. Learning Kotlin.

start kotlin

kotlin star

Kotlin has seen a huge rise in popularity and I can promise you it will only become more popular in the years to come kotlin is an example of a programming language which is a way for me and you to communicate with computers at the end of the day computers only understand binary zeros and ones. so over the years we’ve created many different ways to instruct the computer what we’d like it to do each of these approaches is called a programming language, and you’ve probably heard of some of them such as c or java or javascript .since kotlin was created much more recently it has taken the lessons from the earlier languages to make something that is both powerful and easy to use java and kotlin have a special relationship since they’re compatible with each other kotlin is what java would look like if it was designed today to write kotlin code. Learning Kotlin

IntelliJ IDE

I’m going to be using a program called IntelliJ which you can download for free from the internet to start out with i created an empty file called kotlin minutes the file extension for kotlin files is dot kt and the code we write will be inside this special function called main, we’ll talk more about functions later in classic fashion the first thing we’ll do is print out hello world. so we’ll use this function called println and type in hello world in double-quotes now we’ll execute our code by hitting this green arrow which will compile and run our code compiling just means taking the symbols and keyboards you write and turning that into something that the computer can actually execute you can see the output in this run tool window that pops up where it says hello world as we expect let’s start our tour of kotlin with variables a variable is a piece of data which has a name and a type. Learning Kotlin

Example of code

For example, strings are a sequence of characters so my first name would be stored as a string type the way we’ll declare the variable is with a special keyword called Val you can tell it’s a keyword since it’ll turn a different color in the editor in kotlin every variable must have a type that’s why we say kotlin is statically typed. so in this example, the name of the variable is the first name and the type is a string because we’re setting the value of the variable equal to draw hold right away we actually don’t need to specify that this is of type string this is a nice feature of kotlin called type inference where if it’s obvious what the type is we don’t need to explicitly indicate it there’s also an important concept of whether a variable is read-only or readable and writable if the value of a variable can change after it’s initialized then we have to declare it with this var keyword since my weight goes up every holiday season because of how many cookies I’m eating we’ll use var for that but my first name will never change so that’ll be a vowel there are a few other built-in types.

comment in kotline

In kotlin in addition to string and integer which we just saw for example double is for decimals like 2.5 and booleans only have two values either true or false as you write more code it’s sometimes helpful to leave yourself a note about why you wrote the code in a certain way these are called comments, and you can leave a comment by using a double slash commented lines are ignored by the computer .now that we’ve talked about variables let’s look at operators which allow us to manipulate these variables, for example, we can combine two strings into a longer string with a plus sign which is called concatenation. here we’re printing out the value of s1 plus s2 in this variable called combined so when we run the program we get the result of calling me maybe which is a concatenation of calling me and maybe. this is an example of a binary operator because it takes in two inputs there are several different binary operators for numbers as you might expect with two integers here having value nine and four we can add them together and get thirteen we can also subtract them multiply them divide them or find the remainder after the division with this percent sign that would be 1.


Oh Hi there 👋
It’s nice to meet you.

Sign up to receive awesome content in your inbox, every day..

We don’t spam!


Read Previous

Learning Java in 2022

Read Next

Learning C# In 2022

Leave a Reply

Your email address will not be published. Required fields are marked *