3. About Kotlin
• New programming language that is a pragmatic, safe, concise, and interoperable alternative to
Java.
• With Kotlin, you can implement your projects with less code, a higher level of abstraction, and
fewer annoyances.
• Statically typed programming language (Not like other dynamically typed programming languages
Groovy, JRuby).
• [Note: However, in contrast to Java, Kotlin does not require you to specify the type of every
variable explicitly in your source code. In many cases, the type of a variable can automatically be
determined from context, and in those cases Kotlin allows you to omit the type. Here’s the simplest
possible example of this:
val x = 1]
6. Explanation
• We declare a simple data class with two properties: name and age.
Age is null by default (if it isn’t specified). While creating a list of
persons, you omit Alice’s age, so the default value null is used. Then
you use the function maxBy to find the oldest person in a list. The
lambda expression passed to the function takes one parameter, and
we use "it" as the default name of that parameter. The "elvis"
operator ?: returns zero if the age is null. Because Alice’s age is not
specified, it is considered to be zero, so Bob wins the prize of being
the oldest one.
7. Why?
• The primary goal of Kotlin is to work as a more concise, more
productive and safer alternative to Java, suitable in all contexts where
Java is used today.
8. NullPointerException
• Do you cry out loud every time you see a Null Pointer Exception in
your bug tracker? Then Kotlin is your solution!
• Kotlin’s support for nullable types, which lets you write more reliable
programs by detecting possible null pointer exceptions at compile
time.
9. Where?
• Building server-side code (typically backends of Web applications).
• Building mobile applications that run on Android devices.
• But Kotlin works in other contexts as well. For example, you can use
RoboVM 1 to run Kotlin code on iOS devices. Or you can use Kotlin
together with JavaFX 2 to build desktop applications.
• In addition to Java, Kotlin also can be compiled to JavaScript, allowing
you to run Kotlin code in the browser.
10. Benefit of statically typed language
• Performance: Calling methods is faster because in most cases there is
no need to figure out at runtime which method needs to be called.
• Reliability: The compiler verifies the correctness of the program, so
there are fewer opportunities for crashes at runtime.
• Maintainability: Working with unfamiliar code is easier because you
can see what kind of objects the code is working with.
• Tool support: Static typing enables reliable refactorings, code
completion and other IDE features.