Kotlin or Java
Many articles have been written about the Kotlin and Java programming languages, but many people still wonder the answer of the question:” Kotlin or Java?” I hear the same question from many people close to me. It is a question that is always asked in the job interviews. Why do I prefer Kotlin, is it because of the popular culture and attention or did I make decision consciously? The reason is to measure that though. I don’t even think that I need to warn you guys about not saying “There is something that is called Kotlin. Turns out that everybody is switching to it, so I though why wouldn’t I?” in the job interviews.
A few months after I started working in Peakup, I made a presentation about “Kotlin or Java” to my developer teammates. The same question was asked by students who attended my speech in the IAU Android Talks event of Istanbul Aydın University and the students who came to visit our office from Istanbul Technical University. Which means that everybody who works with programming that much from students to professionals still wonder about the differences of Kotlin and Java. So, I wanted to write an article about this and help people as much as I can. Because I am pretty sure that this question will keep being asked.
In this article, I will try to answer the questions of “Why Kotlin? Is it necessary to know Java for Android programming in 2020? I want to program an Android application, do I need to learn Java? Is Java or Kotlin better for Android? Will Java die or even is it already dead?” Also, I didn’t compare the languages. I just tried to answer if we should switch to Kotlin or when we should switch.
As a summary, I don’t have a simple answer of “Kotlin or Java”, but to sum up the whole article I would say:
“Depends on the situation.”
Depends on the project you will make, if you are a student or not, if you are student; the approach of you university to languages, if you work in the sector or not, if the place you work at has legacy code or not… The answer of this question depends on dozens of variables like these. Instead of wanting just one single answer, please read the article till the end. First of all, the new generation is pretty impatient. They want everything right away, they want to get the answer right away, finish right away, have a great project right away, right away… Please be a bit patient. It is not as clear as black and white. Your life doesn’t have to flow that fast. Inhale, exhale, and live. My answer of “Kotlin or Java” is really long. If you are too lazy to read, I would recommend you to close the tab right now, but I would recommend you to spare some time to read. (If you want to be a developer, you have got to read it obviously.) You may rest assured that you will read an article full of information and it will be worth it.
Unfortunately, the internet has become a huge trash, and it is not possible to distinguish the ones who know something and the ones who don’t. People write just 3-5 lines in a whole page to show a few more advertisements. I want to say in advance that I will not say “Kotlin is good like this, it is good like that” and finish like many articles in the internet. If you want to switch to Kotlin and you need support, you should prefer an article like that. This article will be completely different.
First I want to say that it is important not to be a addict, fanatic, and slave of a language or a technology. I think it is better to be able to switch the language and framework depending on the project and situation. For example, it is wrong to think that we use Java, it has been like this for 20 years and it will keep being like this for 20 more. It is not certain how long the technology, language, and frameworks will be valid. There are so many programming languages and frameworks that were very popular in 2000s and 2010s but now do not even have 1 job advert. We can never know exactly what will happen in this dynamic world.
If you want another example: now, iOS and Android are being developed as native mostly. While we are still discussing if Java or Kotlin is better, Google is developing a cross platform app developing framework called Flutter -which might be the top trend in a few years. Maybe our phones will not have the Android operating system but will have the Fuchsia operation system which is way more stable than Android. For this, I think it is wrong to stick to one language or framework completely and say no to all the other languages.
I can not say that Kotlin is better and throw away the Java culture, sources, and infrastructure coming from 1995 away; or say that definitely Java is better and ignore the innovations and conveniences Kotlin has brought. Now, if you please, let’s dig a little deeper.
1. I am a University student, is Kotlin or Java better for me?
I want to start answering the “Kotlin or Java?” question from the students. If someone asking this question is a student, my recommendations will be a lot different from my recommendations to people who work in the sector. And, it will even depend on the semester and lectures of our dear student.
- What is your major?
- Are you studying a major that has software classes?
- Which semester are you studying at?
- Do you have a Java lecture or Object Oriented Programming (OOP). Did you take this class or will you take it?
If your major is a major like Software Engineering, Computer Engineering, Management Information Systems that has software classes, your semester is of high importance.
1.a ) If you are in your first semester or preparation and if your OOP class will be taught with the Java language
I highly recommend you to check you curriculum if you have come across the “Kotlin or Java” question in your first semester or while you are still prep. Do they teach the OOP class with Java in your university? First, you need to find this out. If you will have a Java or OOP class, the answer of “Java or Kotlin” will definitely be Java. Learning Java will positively affect the grades of you OOP class.
This was a question asked in the speech I gave in Istanbul Aydın University and I asked the student at which semester he was studying. He said he was in the 1st semester and I didn’t give any different answer than above. (I wonder what he is doing now 🙂 ) Start studying Java immediately. Start creating projects and sharing them on GitHub immediately. Don’t worry about the quality of your code right now. It can be good or bad. Even if it is bad, produce and share something. Because in the future employers will care if you have produced something or not. Whenever I come across a software student, I recommend the same thing. Don’t spend your summer without doing anything. After a vacation, sit down and study Java.
1. b ) If you are in your first semester or preparation and your university will teach the OOP class with a programming language other than Java with C#, C++…
You come across the question of Kotlin or Java in the first semester of your university or during the preparatory year, checked your curriculum and learned that C # will be explained. Do not say “I will become an Android Developer anyway, why bother and learn C #”. Do not think that you will waste your time. It is very wrong if you say “C ++ is also used by our university and it does not work.” The aim of the OOP Course is to teach you the basic principles of object oriented programming. It is not teaching you languages. It is not a university programming language course. The university gives you theory that gives you infrastructure. And you get that infrastructure and use it wherever you want. This is up to you. Once you know what OOP is, once you gain the analytical thinking ability, it is not difficult to switch to another object-based language.
One of my professors at Yıldırım Beyazıt University said: “Some of the object-oriented programming languages start the class with import, some with using and some in another way, but the background part of this does not make a big difference between languages. For if while is available in every programming language and is the same. They may be spelled differently, but they do the same job and mean the same thing. If you have learned one Object Oriented language very well, it may take a few weeks to switch to another. “ If we come to the answer of the question of Kotlin or Java, do not rush to learn Kotlin.
Study the language you will see in your OOP class. No matter what language it is, study that language and pass your OOP lesson with good grades. If you want to learn Android programming afterwards, you don’t need to learn Java again. You can start from Kotlin. The fundamentals of object-oriented programming are essential. Algorithms, Design Patterns, Software principles, Code standards … You learn the language very well in whatever language your university teaches. You may rest assured that it will be much easier for you to switch to Kotlin in the future.
1. c ) If you have come across this question after the 5th semester of the university
OOP class is just water under the bridge now. And you didn’t get enough of this lesson. Or you have never taken this class. Or it was elective and was taught by a hard teacher and you just didn’t take it. (It is a big mistake if you think to become a developer when you graduate. If you have not decided what you will be when you graduate, it is the subject of a very different article 🙂 In this case, if your university taught you any object-based language,
you can start from Kotlin. I think there is no university that does not show any software language or at least teach OOP principles, but the quality has dropped everywhere since universities are everywhere. Maybe there are universities like that, so I should add the following. If you know the basics of programming but also lack some stuff, I wouldn’t recommend starting Kotlin. Start with Java. Because you don’t have resource problems in Java. You can find dozens of books, dozens of blogs and videos, and you can go a long way in a short time. There are various Kotlin sources, but I don’t think they can compete with Java’s resources.
As a result, if you have obtained a good OOP information from your university, it doesn’t matter what language you were taught in. I will answer the “Kotlin or Java?” question as Kotlin. If you have prepared your programming infrastructure well enough, if you have gained analytical thinking skills, you will be able to produce a small project in a few weeks in another OOP language you want.
2. I am Already Working as an Android Developer, So, Kotlin or Java, Which is Better?
If you are already working as an Android Developer in a company and asking whether it is Kotlin or Java, my answer will not be Kotlin. I will suggest that you eventually switch to Kotlin. Since you already know Java above a certain level, you know the concepts of OOP, it will not be difficult for you to switch to Kotlin. Switch to Kotlin, but it’s not like everyone has to switch right away. I will ask you a few questions like I asked the students to suggest when to switch.
- How big are your projects in the company now?
- How innovative is your company and do your managers support your desire to improve yourself?
- How many users are actively using the application you have already made with Java?
- Is it expected by the user that you constantly release fixes and updates to the application you want to switch to Kotlin?
You are fresh out of uni and you were taught Java in university. You started to write Android applications with Java, and you entered a start-up company. You have been working for 3 months. You have had 2 small Android applications and used Java in them. I will recommend you to continue with Java in this company for a while. In your case, unfortunately, you don’t have time to spare for Kotlin right now. You have to prove yourself to the employer to produce results in the short term. I know that feeling very well. When you change jobs, or overthrow an important milestone at this workplace such as 6 months, 8 months, 1 year, I recommend that you spend a little time with Kotlin and work in free time. Then you gradually integrate it into your company projects.
Just because Kotlin has come out and is easier than Java, switching a big project you have developed with Java for 2 3 years to Kotlin may cause unwanted results. While you are still learning about Kotlin, you may get confused, have difficulties and lose motivation because you have started with the big project directly. Like the mistake I made before: You can write Kotlin, but you will write Kotlin like Java.
I cannot help but mention that, in PEAKUP, time and resources are always allocated and created for every person who wants to improve themselves.
There is also the user side of all this, which I think is a more important topic than both being innovative and your managers. Dozens of users use the application you write in Java and if the user is expected to make continuous improvements, it may be difficult to switch to Kotlin. My humble advice would be to definitely work with Kotlin outside of your working hours and make a few medium-sized projects using Kotlin, and if the user allows, open a side branch and gradually transfer your project to Kotlin. Thus, you do not affect the main branch and you can go to the main branch at any time, make an error correction, add a feature, and then return to the Kotlin migration branch.
- If your managers give you time to improve yourself
- If you are new to the company and your company has never written a Native Android application before (the situation I came across when I started in Peakup)
- If your existing Android applications written in Java are stable, error correction and feature additions are not too much
In the situations listed above, I would say start Kotlin as soon as possible without thinking for even a minute. If you are starting a project from scratch, start directly with Kotlin. If you don’t know, you will just learn, and learning Kotlin by doing a project is the best learning method. As our ancestors said, make it up as you go along, small is the seed of every greatness…
Will Android Give Up Java Completely?
It is a very sweet and cute question of your colleagues or job interviews. It does not seem possible for Android to give up Java at the moment. Because there are millions of lines of Java code in the Android operating system. There are dozens of applications written only in Java in the Google Play Store. On the other hand, there is a situation that Android Studio has been developed so much that when you paste Java code into a Kotlin project (if there is no syntax error in the code you paste), it automatically turns into Kotlin code. While Google hype Kotlin at every event and praises it at length, it doesn’t make a good or bad statement about Java. In my personal opinion, it would be wrong not to switch to Kotlin when even Android Studio shouts so much for Kotlin. Over time, this transition will be made concretely even by Google. One day is will for sure, but not today.
My Story of Starting Kotlin
I want to talk briefly about how I learned Kotlin. I learned Java in university. I don’t regret it a bit. If I were to go to university again with the consciousness I have today, I would want to learn Java instead of Kotlin again. There are no sources that you cannot find about Java, but it is a huge problem for Kotlin. Kotlin still gets support from Java about many topics.
We got a good knowledge of OOP from our Java teacher who is not Turkish and does not speak Turkish. Also, the previous summer I also studied Java on my own, of course, this had an effect. Again, it is one of the suggestions that I have applied and benefited from and that I give students frequently. Studying the classes you will take the previous summer in advance.
After university, I developed Android applications using Java for 2 years. Then Kotlin was declared as the official language by Google, and I was yearning to learn Kotlin, but I couldn’t get started right away. Because there was a huge shortage of resources and the environment such as let’s switch to Kotlin immediately did not occur at my workplace at that time. We had more of an approach – as it should be – let’s see what the situation will be, but when I found out how much it shortens the code and its conveniences, I was really enthusiastic. In 2017, when Kotlin’s learning resources increased during the year, I started to write small-scale projects on my personal blog, but after a while I got stuck. Why and where did I get stuck?
So, Do I Know Kotlin?
Saying “I learned Kotlin” or “I know Kotlin” would be way too pretentious. I needed to do larger-scale projects to say something like this. I tried to do that as much as I could. I rewrote an old medium-sized project from scratch using Kotlin. I was ready to start integrating it into projects at work and then I went to perform my military service. And I acquired a Kotlin book in the military and continued to work with Kotlin. After my military service, I got a job at PEAKUP and started every project I started from scratch here with Kotlin. Well, do I know Kotlin? I still cannot give an answer to this question like “I know very well, if they did the exam, I would get 100, I know 10 out of 10 “. And, what even is the criterion to be able to say that I know a language? That is also a very different matter.
Is Java Dead, Will It Die?
Guys, Java is not a language that would just die easily. Java existed before Android and has never been dependent on Android. There is Oracle -one of the biggest technology companies of the world- behind Java. With that big of a support, non-stop investments, and thousand of developers; Java is not a language to die and be forgotten. I don’t know what will happen 20 years later, but I don’t think that it is that hard to see the 3-5 years from today. According to many authorities, it is among the 5 most used languages in the world. Oracle might be having a hard time keeping up with technology. There are many open source rivals in products and its work, but the main product of Oracle is hardware. In dozens of machines we use, Oracle products are working. Can it become the IBM of the world in time? Could be. Oracle might fall, but not soon. Even if Oracle becomes poor, Java could die if its developers die and universities turn away from it.
Click here to read the article where I talked about SwiftUI and Jetpack Compose.