Monday, October 3, 2016

Why I Won’t Be Using Java for My Next Android Project

     Ever since its inception in 1996, Java has been no stranger to criticism. Nevertheless, it’s popularity has only continued to grow in recent years. A lot of this recent growth is due to the widespread usage of the Android platform. Before Android, Java’s verbosity was a favorite among project managers because it made it look like people were getting a lot of work done. In its early days, Java even had a purpose, to provide somewhat-secure, cross-platform web apps. But is the Sun (pun intended) about to set on the Java empire? Recent trends show that more programmers are turning away from this twenty-year-old behemoth named after a coffee bean.

     In 2016 alone, we’ve seen fewer web apps using Java, JetBrains releasing the Kotlin language for JVM, and there are even rumors of Swift for Android. We don’t have any word from the project managers yet but we can reasonably expect them to migrate from Java by the time the aliens return.


     While we wait for that day to come, we as developers can take a stand. While I’ll likely be using Java for the remainder of my Udacity projects, personal projects are a different story. But why exactly is choosing a Java alternative so appealing when building an Android app? Here are my main reasons.

Verbosity:

     Project managers aside, no one needs verbose code. Unfortunately, Java has a lot of these problems. We need to reference a class name at least twice in order to initialize it. This is even worse than it sounds, given that Java class names are notoriously long. Many modern languages are still statically typed, but have proper type inference, which fixes this problem. What about parentheses after conditional and loop conditions? Most modern languages don’t need those either. Add in other features like the “new” keyword and a semicolon after every line, and you’re sure to have a mess of code.

Closures:

     When first learning Groovy to write Gradle scripts, I couldn’t help but applaud the use of closures. This excellent feature from Swift has already taken the iOS community by storm, and Groovy closures should really be doing the same for Android. Ever used AsyncTask or Runnable? You may have noticed that only static properties (from the class calling it) can be used in their methods. Closures, on the other hand, are methods that don’t need to belong to a class. You can use any variable from the class that’s using it. We could finally see a proper completion handler pattern for Android, which would make networking code and long running tasks much more readable.

Protocols:

     While Swift for Android is still a long wait away, Swift-like features such as protocol oriented programming could be very handy in Android apps. Protocols are much more flexible than java interfaces, with features such as optional methods. The ability to use protocols would allow for much cleaner MVC design.

Typing Time:

     This goes without saying, having previously mentioned Java’s verbosity. All this unneeded syntax wastes a lot of typing time. In an age where compiled languages that read like scripting languages are common, it’s hard to make an argument in favor of the old conventions. Building software is supposed to be about productivity. Unless you’re in a workplace that measures lines of code, using a Java replacement is something to consider.

NullPointerException:

     Even the experienced programmer encounters some of these. While no magical new programming language can eliminate null pointers, there are many better ways of handling these cases. In java, before using a class that may be equal to null, you need to check if it’s “!= null” or use “instanceof”. In many cases, this is necessary simply to call a single method. Instead, if you use Kotlin or Groovy, there are special operators that can handle null pointer exceptions for you, without needing to add an extra level of indenting.

The Future:

     It took Apple 30 years to finally do something about Objective-C, so Java still has a good 10 years to live. But if you have the choice, the advantages of using an alternative are clear. From saving time to advanced features, Java replacements can greatly improve your Android development productivity. For me personally, I’ll soon be porting an iOS app I wrote over to Android. I don’t intend to use a single line of Java. The only question is: who’s it gonna be?

Kotlin, Groovy, or something else? Let me know in the comments and I'll keep you posted when I start porting the app.

30 comments:

  1. I have read your blog its very attractive and impressive. I like it your blog.

    Java Training in Chennai Core Java Training in Chennai Core Java Training in Chennai

    Java Online Training Java Online Training JavaEE Training in Chennai Java EE Training in Chennai

    ReplyDelete
    Replies
    1. Great Article android based projects

      Java Training in Chennai

      Project Center in Chennai

      Java Training in Chennai

      projects for cse

      The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

      Delete
  2. The ability to have the same online gaming experience, regardless of the computer hardware that you have, has been made possible through the creation and continued development of Flash and Java Script - which are both programming languages.
    StartPoint

    ReplyDelete
  3. This type of message always inspiring and I prefer to read quality content, so happy to find good place to many here in the post, the writing is just great, thanks for the post. Techomash

    ReplyDelete
  4. Really a great addition. I have read this marvelous post. Thanks for sharing information about it. I really like that. Thanks so lot for your convene. Download UC browser mini

    ReplyDelete
  5. I have bookmarked your blog, the articles are way better than other similar blogs.. thanks for a great blog! 9apps

    ReplyDelete
  6. Java is a good language but better go with other languages for android programming than going with Java!
    Hack Summoners War

    ReplyDelete
  7. Looking to get the best Hack Tool for Battle Cats? We have made a working one that can add unlimited resources for free!
    Visit - Hack Now

    ReplyDelete
  8. If you are always on the look for brand new games to download, worry no more with the easy access to Android games. COC Free Gems

    ReplyDelete
  9. Most of the time I don’t make comments on websites, but I'd like to say that this article really forced me to do so. Really nice post! ACMarket

    ReplyDelete
  10. Great write-up, I am a big believer in commenting on blogs to inform the blog writers know that they’ve added something worthwhile to the world wide web!.. Snapchat++

    ReplyDelete
  11. Thanks for sharing the post.. parents are worlds best person in each lives of individual..they need or must succeed to sustain needs of the family. Emus4u

    ReplyDelete
  12. Really a great addition. I have read this marvelous post. Thanks for sharing information about it. I really like that. Thanks so lot for your convene.
    Happy mothers day Quotes

    ReplyDelete
  13. This is such a great resource that you are providing and you give it away for free. I love seeing websites that understand the value of providing a quality resource for free. It is the old what goes around comes around routine. AirShou iOS 10

    ReplyDelete
  14. This is such a great resource that you are providing and you give it away for free. I love seeing websites that understand the value of providing a quality resource for free. It is the old what goes around comes around routine. AntiRevoke iOS 11

    ReplyDelete
  15. Excellent information on your blog, thank you for taking the time to share with us. Amazing insight you have on this, it's nice to find a website that details so much information about different artists. Cydia iOS 11.3

    ReplyDelete
  16. Great post I would like to thank you for the efforts you have made in writing this interesting and knowledgeable article. download 9apps

    ReplyDelete
  17. thanks for the tips and information..i really appreciate it.. sword man monster hack

    ReplyDelete
  18. You have done a great job on this article. It’s very readable and highly intelligent. You have even managed to make it understandable and easy to read. You have some real writing talent. Thank you. Learn more on our website

    ReplyDelete
  19. This is the type of information I’ve long been trying to find. Thank you for writing this information. vidmate download

    ReplyDelete
  20. thanks for this usefull article, waiting for this article like this again. gta vice city apk obb

    ReplyDelete
  21. I have found the latest version of Clash of clans mod Apk on the site they always update the game,

    ReplyDelete
  22. Got big winnings at once? Then come to us and get even more. best slot casino Win more with us.

    ReplyDelete
  23. This is a blog you can get useful information and better stuff right here click here

    ReplyDelete
  24. Das Rooting ermöglicht es dem Gerät, die Installation einer Vielzahl von Drittanbieteranwendungen einschließlich Spionageprogrammen zu akzeptieren. whatsapp gruppe hacken Oder nutzen Sie das Telefon als Wi-Fi-Hotspot für Ihren Laptop zu Hause.

    ReplyDelete