Java vs Kotlin for Android App Development

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
kahlan or Java for Android development which one should you use that is the question a little bit of background about myself I did my master's thesis on security within the Android operating system and I have done some app development mostly in Java so this is how the video is going to go first we're gonna see how we got to the current state of things why are we even comparing these languages secondly we're gonna compare the languages from a technical point of view and finally I'm gonna give my opinion on which language I think you should use before we get started make sure you guys hit that like button let's try to get this video up to 200 likes I know you guys can do it so first let's talk about Java and Android so we have to go back in time a little bit initially we had this language called C and they wanted to add object-oriented programming to this so basically they just slapped on the ability to create classes and it was even called C with classes which they found out was a really lame name so they later renamed it to C++ which sounds much cooler and it was kind of an awkward implementation of object-oriented programming like the objects were really dumb and people were just complaining about its limitations so in 1995 this guy at Sun Microsystems created Java and it was really built from the ground up with object-oriented programming in mind it was just a lot more intuitive the objects were a lot smarter but eventually Sun Microsystems was acquired by Oracle giving Oracle the rights to Java so fast forward a little bit 2008 Google Forks the Linux operating system and creates Android which today Android is used not only in smartphones but tablets smart TVs smart refrigerators and even though the Android operating system is written in C as most operating systems are the app development aspect of it was written using Java and since Java natively doesn't have support for developing Android applications Google developed the Android SDK which allows you to create apps using Java well Oracle didn't take much pleasure in this and they ended up suing Google and this has been a nasty lawsuit that's been going on for like 10 years and is even still going on so what has Google done in the mean time well they're basically like we need move away from java as soon as possible and how they did this was by working with a company called JetBrains now JetBrains is a Czech based company that develops tools for software developers their main product is IntelliJ which is an IDE that's used for developing in Java and what they did is they took IntelliJ they made a fork of it and created Android studio and this was really the first stand-alone app for Android development because before people had to use Eclipse and they had to add a bunch of plugins and it was really buggy and honestly it was just a nightmare to set things up so the creation of Android studio was a huge breakthrough and a huge leap for Android development now why am I talking about JetBrains well there are actually the developers of the cotton lint programming language they developed this in 2011 and it's very similar to Java in that it uses the Java Virtual Machine as we see here initially in Java you'd have your java code your java compiler compiles that code into what's called byte code or dot class files and now any operating system that has the JVM on it can read byte code now Kotlin also compiled to bytecode basically you have your callin code it goes through the collin compiler and then it ends up as bytecode so it's not like you need to change your entire architecture if you want to switch over to calling you really just swap out the Java code and the Java compiler and there you go you have Collin that compiles down to byte code and in 2019 Google announced that Kotlin will be the official language for Android app development going forward so now that we're caught up with where we're at today let's take a look at a technical comparison of these two languages so the first difference is that Kotlin is null safe so in Java you can set your objects to be equal to null but you have the possibility of china reference and no object and getting a null pointer exception and honestly this is really dangerous because you a lot of times you won't be able to catch this until runtime and collin was basically like we don't trust the programmers to do this we're just not gonna allow any of the objects to be knowable there is a way to override that but you have to do it explicitly so this is one of the safety features that like about Kotlin next up Colin gives you the ability to extend existing classes with new functionality now you can do this in Java but if you want to you have to create a new class you have to inherit from that parent class and then override your function in there and Colin for an example say we want to add a method to the string class you don't need to create a new class for this you can simply do string dot last char to define a new method and then going forward every string will have that dot last char method which will save you a lot of code so you just want to extend one function you don't need to create a whole new class for that one negative of Colin is that you don't have checked exceptions whereas in Java this is required which ultimately leads to robust code with better error handling Colin gives you the ability to have data classes so if you just have a class that needs to store data and nothing else you simply declare a class with the keyword data and the compiler takes care of everything like creating the constructors the getters and setters whereas in Java you would have to explicitly write all that code Kotlin also has type inference so say in Java you want to create an integer you have to do ok int I equals 10 or string s equals Sam in Kotlin you can simply write something like var I equals 10 and the program is smart enough to know that this is an integer so how could this be helpful well say you have a variable and you want to set it to the return value of a function say later on you change the data type that that function returns well you don't need to go back and also change the variable whereas in Java anytime that you do have that variable you would have to go through and change it to whatever datatype you change the method to all right so what's what's my opinion on this well let's go back to 2014 Apple announced that they've released a new programming language - called Swift now up until that point all iOS app development was done in objective-c and I remember people were asking you know like what like what's going on here are people gonna switch over to Swift is objective-c gonna die and people were like should I even learn Swift because you know every has been built an objective-c I don't know if everyone's just gonna transition over to Swift and I remember thinking like you know Apple wouldn't put resources into this if they weren't really serious about it they're the ones that created iOS app development if they want Swift to succeed they're gonna be able to do it and now we fast forward six years later 2020 no one's really developing apps and Objective C anymore so I really think that something similar is gonna happen with Android I think Google just wants nothing to do with Java anymore and I honestly wouldn't be surprised if they stopped support for Java you know if you're a few years down the line but you know if you're new to Android development and you're already you know if you're already good at Java I would say at that point just stick with Java I don't really think it's worth it to learn a brand new language however if you're a professional app developer or you're trying to be you know why wouldn't you go the common route why wouldn't you go against something that why wouldn't you go for something that Google is pushing for so that's really my opinion I would choose Colin over Java for Android development but yeah I would love to hear your guy's opinion so let me know in the comments which one you think is better but yeah that's gonna be it for this video thank you guys so much for watching hopefully you guys found it interesting hopefully you guys learned something I know I definitely had to look up some stuff with Kotlin and I learned a lot about it and honestly I I really like the language and I'm I might even consider studying it more and trying to get better at it but as always thank you guys so much for watching and happy coding [Music] you
Info
Channel: Keep On Coding
Views: 127,601
Rating: 4.9423652 out of 5
Keywords: java vs kotlin, kotlin vs java, kotlin android, java android, android app development
Id: 9wWgw9smBJs
Channel Id: undefined
Length: 8min 22sec (502 seconds)
Published: Wed May 13 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.