Know more about Kotlin


Kotlin is a statically-typed programming language that runs on the Java Virtual Machine and also can be compiled to JavaScript source code or uses the LLVM compiler infrastructure.

Know more about Kotlin?
Kotlin, as described before, is a JVM based language developed by Jet Brains a company known for creating IntelliJ IDEA, a powerful IDE for Java development.

Android Studio, the official Android IDE, is based on IntelliJ.
Kotlin was created with Java developers in mind, and with IntelliJ as its main development IDE. And these are two very interesting features for Android developers:

Kotlin is very intuitive and easy to learn for Java developers. Most parts of the language are very similar to what we already know, and the differences in basic concepts can be learnt in no time.

We have total integration with our daily IDE for free. Android Studio can understand, compile and run Kotlin code. And the support for this language comes from the company who develops the IDE, so we Android developers are first-class citizens

But this is only related to how the language integrates with our tools. What are the advantages of the language when compared to Java 6?

It’s more expressive: this is one of its most important qualities. You can write more with much less code.

It’s safer: Kotlin is null safe, which means that we deal with possible null situations in compile time, to prevent execution time exceptions. We need to explicitly specify that an object can be null, and then check its nullity before using it. You will save a lot of time debugging null pointer exceptions and fixing nullity bugs.

It’s functional: Kotlin is basically an object oriented language, not a pure functional language. However, as many other modern languages, it uses many concepts from functional programming, such as lambda expressions, to solve some problems in a much easier way. Another nice feature is the way it deals with collections.

It makes use of extension functions: This means we can extend any class with new features even if we don’t have access to the source code.

It’s highly interoperable: You can continue using most libraries and code written in Java, because the interoperability between both languages is excellent. It’s even possible to create mixed projects, with both Kotlin and Java files coexisting.

if we want to create a
data class, we’ll need to write (or at least generate) this code:

1 public class Artist {
2 private long id;
3 private String name;
4 private String url;
5 private String mbid;
6
7 public long getId() {
8 return id;
9 }
10
11 public void setId(long id) {
12 this.id = id;
13 }
14
15 public String getName() {
16 return name;
17 }
18
19 public void setName(String name) {
20 this.name = name;
21 }
22
23 public String getUrl() {
24 return url;
25 }
26
27 public void setUrl(String url) {
28 this.url = url;
29 }
30
31 public String getMbid() {
32 return mbid;
33 }
34
35 public void setMbid(String mbid) {
36 this.mbid = mbid;
1 Introduction 7
37 }
38
39 @Override public String toString() {
40 return "Artist{" +
41 "id=" + id +
42 ", name='" + name + '\'' +
43 ", url='" + url + '\'' +
44 ", mbid='" + mbid + '\'' +
45 '}';
46 }
47 }

With Kotlin, you just need to make use of a data class:
1 data class Artist(
2 var id: Long,
3 var name: String,
4 var url: String,
5 var mbid: String)

Leave a Reply

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