How did the giants rise? Episode I

Mustafa Selim Özen
6 min readJun 15, 2022

--

Introduction to Kotlin

“If I have seen further than others, it is by standing upon the shoulders of giants.”

At first, Isaac Newton disliked scientists before him, but later he uttered the word to show his respect to the scientists before him. This analogy created in my mind a great science tower of giant scientists standing on each other’s shoulders. But lately, I feel like we’re not rising, no matter how hard we step on the shoulders of giants. This may indeed be a misconception. Don’t be fooled by my opinion. But I must explain why I think so. Because in the old days, when there were not so many books, when it was difficult to reach the existing books, we made great progress when there was no internet and electricity. I’m talking about the 1950s. Quantum discoveries, artificial intelligence articles, the beginning of the space age.I’m not saying there is no progress. It seems as if there is little progress when only information is so much and easily accessible? I’m really curious about your opinion on this matter.

But of course we’re not here for Newton’s shoulders. While browsing platforms like LinkedIn, I saw that some software giants complain that new generation software developers are just adaptors and are far from the main issues about software. They state that we are far from writing algorithms, and we only use frameworks. I would like to thank the giants for the frameworks, libraries they developed and the solutions they found. In this adventure, I will get off the shoulders of giants and try to understand how they stand. Then maybe one day they can step on my shoulders too.

What is Kotlin?

Kotlin is a programming language that was started to be developed by Jetbrain developers in 2010 and became open source in 2012. It is a static programming language. It can also be used in object-oriented programming.

Why Kotlin?

At an event in 2019, Google announced the Kotlin language as an official development tool for Android. A rival to the Java language was born. Many companies from large companies to Start-ups have started to use Kotlin. According to Google, 60% of the most downloaded apps in the Play Store are developed with Kotlin. With KMM, it is now possible to develop applications on the IOS platform.

How Does Kotlin Work?

Kotlin works by converting to bytes on the JVM side. Actually, I said rivals, but they are not rivals. They’re like brothers. Kotlin can run wherever Java is. Kotlin and Java are interoperable. Let’s talk in more detail. Kotlin's codes are usually kept in .kt files. The Kotlin compiler analyzes the codes and creates .class files from these codes. Lastly, these codes are converted to the application you are working on. Java language also has this process. You can download Intellij Idea vs Android Studio to use Kotlin.

Introduction To Kotlin Data Types

Variables are indispensable parts of programming. At first we will define it ourselves to learn, but then we will use it when making games and extracting data from the internet.

Let’s start with an example.

var x = "Mr. Selim, You are Welcome."
val episode = 1

Here we have defined 2 variables. In Kotlin, if we are defining a variable for the first time, we have to define it using val or var. Variables defined with var can always be changed, but we cannot change variables defined with val. If i define

episode = 2

“Kotlin: Val cannot be reassigned” this way we will get an error. You can change the variable that starts with var as you wish.

x = "Mr. Ozen, You are welcome!"
println(x)

Output:

Mr. Ozen, You are welcome!

Basic Data Types

We will start with numeric data types. We can talk about 6 types of numeric data types. Four of them are byte, short, integer and long. The order I have given you is the order from smallest to largest. Why is this important? Because most of the time, we have to make an optimization in memory usage. In other words, small data types for the application to run fast and take up little space. Sometimes we may need to work with very large numbers. For such cases, we have to work with different data types, but generally integer is used. Let’s first look at how the data is defined, then how can we see the size of the data?

var x = 10

In this way, we have defined an integer data type, but if you want, we can first define the type of the data and then initialize it.

var z : Byte
z = 75

Other examples

var v : Long
v = 7525563

Now if you want, let’s look at the size, at the same time, let’s start learning how to use the println command.

var minbyte = Byte.MIN_VALUE
var maxbyte = Byte.MAX_VALUE
println(minbyte)
println(maxbyte)
Output:
-128
127

For now, we print simple variables to the console with the println command. In the future, it will be very important to see if our project is working correctly. Another use could be like this:

println("Minimum short size ${Short.MIN_VALUE}, and maximum size ${Short.MAX_VALUE}")
println("Minimum integer size ${Int.MIN_VALUE}, and maximum size ${Int.MAX_VALUE}")
println("Minimum long size ${Long.MIN_VALUE}, and maximum size ${Long.MAX_VALUE}")

Output:

Minimum byte size -32768, and maximum size 32767
Minimum byte size -2147483648, and maximum size 2147483647
Minimum byte size -9223372036854775808, and maximum size 9223372036854775807

Our other numeric data types are float and double. These data types are used for fractional numbers. In these data types, the smaller float is the larger double. As for how we define it, if you define a fractional number, it will define double by default.

val euler = 2.718

but you can define it this way too

val pi : Double = 3.14

but these numbers are actually small numbers to define double. We can define floats for these numbers.

val pisconstant = 1.41421f

If you noticed, it says ‘f’ at the end of the number. This is how it is specified that the variable is a float data type.

String Data Type

String data types are actually data types containing text. You can define any type of text with this data type. All you have to do is use quotation marks.

var name = "Nicola"
//or
var sirname : String = "Tesla"

We haven’t touched on this yet. Actually, we mentioned above. These all are primitive data types, but still reference’s of classes. Why is this important? Because you can use many features of these classes, speed up your work and make it easier.

//It's not about classes. For example only. 
//so you can concatenate strings like this.
var scientist = name + " " + sirname
//for example, you can get the length of the text
println(scientist.length)

Output:

12

by the way, you can see the parts starting with ‘//’. These are informative comment lines. You can also take notes or give information to someone else by using it in your codes. Let’s continue.

//You can check if the strings are equal to each other
var s1 = "programming is simple"
var s2 = "I don't know anything about programming."
var s3 = "programming is simple"
println(s1 == s2)
println(s1 == s3)

Output:

false

false and true are actually our next data type. We can make many examples about strings, but I recommend you to research according to your needs. Let’s move on to the Boolean data type. (By the way, the first check should have returned true.)

Boolean

Boolean data types take only 2 types of values. Right and wrong. We use them in general if checks. Or the operators that we will see in the next sections. Let’s do a few examples for now.

println(3 > 5)
var comment = "Led Zeppelin!!"
println(comment == "Led Zeppelin!!")

Output:

falsetrue

We have learned almost all primitive data types and when you read this article, you have taken the first step to become a giant.

Resources:

Cover Photo: https://tr.pinterest.com/pin/141230138300769505/

Compiler’s Photo:

https://www.udemy.com/course/android-o-mobil-uygulama-dersi-kotlin-java/

--

--