The Chronicles Of Kotlin 2

Good evening guys, trust you are doing well. I would continue this second part on my chronicles of Kotlin. The agenda today are below:

  • Kotlin as a statically typed language

  • Kotlin as a JVM language

  • Kotlin support for data immutability

  • Kotlin support for nullPointer Exception

  • Kotlin as an object oriented language

  • Kotlin support for functional programming

  • Lesser code, more result.

  1. Kotlin as a statically typed language means type checking is done at compiler. This means the developer explicitly states the data type for the variables while writing the code. The main advantage here is that all kinds of checking can be done by the compiler, and therefore a lot of trivial bugs are caught at a very early stage. In this situation, there is no need to carry out type checking at execution phase because contrasting data types are checked and errors indicated at compilation. Kotlin as well have this features, the data types are declared at compilation stage. carbon.png

  2. Kotlin as a JVM language: This means kotlin relies on the Java Virtual Machine to compile its codes into bytecode. Kotlin produces bytecodes that are JVM compatible, and as JVM is platform independent, this makes Kotlin as well platform independent. In the heart of kotlin code execution is a Java Virtual Machine, this accounts for the reason for installing Java Development Kit among the tool kits for writing programs with Kotlin.

  3. Kotlin support for data immutability: There are two keywords used to declare data in Kotlin. The first is "var" and the second "val". Var is used to declare and initialise variables that can still be reinitialised (or value changed). However, val is used to declare variables that are immutable( cannot be reinitialised). Hence, var is used for writable variable while val is for read only. Kotlin immediately indicates an error while writing the code.

  4. Kotlin support for nullPointer Exception: Kotlin was designed to avoid some common errors programmers have been facing, among which is null pointer reference. This is a value which is used to state that the reference is not a valid object. By convention, the null pointers is used to reference situations such as the end of a list with unknown length. This means a pointer to an address on the memory space that does not have a valid value hence it cannot be referenced while calling the program, hence it often result in an unhandled error such as segmentation error in C. Kotlin avoid this error at compilation, and this never gets to the runtime. It does this by making a null illegal for standard types. In order to use null, kotlin adds a safe call ? or ?. carbon (1).png

  5. Kotlin as an object oriented language: Kotlin implements object oriented phenomenons such as abstraction, inheritance, polymorphism among others. These would be discussed in details later. However, the get it is that kotlin implements the concepts of classes and objects, and these classes have properties and methods. These properties and methods are the data that are transacted in a program using kotlin syntax.

  6. Kotlin support for functional programming: as much as kotlin supports object oriented programming, it supports passing functions as parameters to a functions, passing functions as data and returning functions like returning data. It also supports lambda functions as well.

  7. Lesser code, more result: when compared with Java, Kotlin does a lot with a little. This makes kotlin codes simpler and shorter with higher level of efficiency. carbon (2).png

And that's it guys, you can share your views and opinions in the comment section please. Look forward to further materials and contents in line with android development.

Thanks.