loading...
Cover image for Java In 2019 And Beyond

Java In 2019 And Beyond

lemuelogbunude profile image Lemuel Ogbunude ・6 min read

What comes to your mind when you hear the word Java?

For some people, they remember a very verbose programming language taught to them in their CS class, for some others, they have heard of it probably because of its popularity.

Some... just hate Java.

Amongst all these, Java is still currently one of the top hot languages today, why is this so?

The Java You Know

A lot of people learnt Java in their early years of programming, some went on to love it while others went on to hate it.

Unfortunately, people use the Java they previously learnt years ago to judge modern Java.

Quoting the words of Venkat Subramanian he said "Java development has been by far the best in the past 5 years compared to the past 20 years, and I am going to put my money on this, the development in the space of Java would be the biggest in the next 3 to 4 years than we have ever seen"

I would try to show you some areas where Java has improved though Java has improved way more than I would show here.

Let us use some examples, in this example, I would use the old Java you probably know and then I would show you how you might solve the problem using Modern Java.

Let's say your lecturer told you to create a program to create a list of integers from 1 to 10 and then loop through it to print out the even numbers, using old Java your code might look like this:

      ArrayList<Integer> myList = new ArrayList<Integer>();

        for (int i = 1; i <= 10; i++) {
            myList.add(i);
        }

        for (int num : myList) {
            if (num % 2 == 0)
                System.out.println(num);
        }

If you have used other languages then the code above might make you desire a simpler and less complex solution.

Using modern Java, I could make the code above easier on the eyes by writing it using the style below:

      rangeClosed(1, 10).boxed().collect(Collectors.toList())
                .stream()
                .filter(integer -> integer % 2 == 0)
                .forEach(System.out::println);

I think that's better looking.

Java has been known to be a language where you have to state every single detail before you can get a little thing done, so using the Java you know, creating a Hashmap would look like this:

HashMap<Integer, String> myMap = new HashMap<Integer, String>();

Well, I would like that to be more concise.

Fortunately, Java currently does not need all that boilerplate code:

var myMap = new HashMap<Integer, String>();

I am not here to convince you that Java is the most concise language, but I am here to tell you that Java is probably way less verbose and way more concise than you last met it.

Modern Java

I would list out some improvements in Java, take note, this is nowhere an exhaustive list and there are way more improvements than I would mention here.

If I tried to mention all the improvements, I would have enough content to publish a book about it.

JShell

The Java Shell tool (JShell) is an interactive tool for learning the Java programming language and prototyping Java code.

JShell is a Read-Evaluate-Print Loop (REPL), which evaluates declarations, statements, and expressions as they are entered and immediately shows the results. The tool is run from the command line.

JShell

You can test individual statements, try out different variations of a method, and experiment with unfamiliar APIs within the JShell session.

It was added in JDK 9, it's quite a useful tool, might be a lifesaver one of these days.

Switch Expressions

Switch expressions are expected to be in JDK 12+, they simplify the traditional switch statements we know, for example, the code:

switch (day) {
    case MONDAY:
    case FRIDAY:
    case SUNDAY:
        System.out.println(6);
        break;
    case TUESDAY:
        System.out.println(7);
        break;
    case THURSDAY:
    case SATURDAY:
        System.out.println(8);
        break;
    case WEDNESDAY:
        System.out.println(9);
        break;
}

Would be written as:

switch (day) {
    case MONDAY, FRIDAY, SUNDAY -> System.out.println(6);
    case TUESDAY                -> System.out.println(7);
    case THURSDAY, SATURDAY     -> System.out.println(8);
    case WEDNESDAY              -> System.out.println(9);
}

CompletableFuture (The Promises of Java)

CompletableFuture allows the creation and execution of chains of asynchronous tasks.

CompletableFuture works the same way Promises work in JavaScript.

    public static void main(String[] args) throws InterruptedException {

        CompletableFuture.supplyAsync(() -> longProcess()).thenAccept(System.out::println);
        Thread.sleep(4000);
        System.out.println("Done!");
    }

    private static int longProcess() {
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return 1;
    }

CompletableFuture was introduced in JDK 8, though people focused on the shiny new Java streams and didn't notice the wonderful tool.

If you are interested you could go watch and learn about it:

Project Loom

Project Loom, which is not yet fully implemented, will introduce fibers as lightweight, efficient threads managed by the Java Virtual Machine, that let developers use the same simple abstraction but with better performance and lower footprint.

Fibers are much more lightweight than kernel threads in terms of memory footprint, and the overhead of task-switching among them is close to zero.

Millions of fibers can be spawned in a single JVM instance, and programmers need not hesitate to issue synchronous, blocking calls, as blocking will be virtually free.

Records (Data classes for Java)

Records, which is also a feature yet to be implemented, is going to help make creating POJO classes easier. For example a class such as:

class Point {
    double x;
    double y;

    Point(double x, double y) {
        this.x = x;
        this.y = y;
    }

    public void setX(double x) {
        this.x = x;
    }

    public double getX() {
        return x;
    }

    public void setY(double y) {
        this.y = y;
    }

    public double getY() {
        return y;
    }

    @Override
    public int hashCode() {
        return super.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        return super.equals(obj);
    }


    @Override
    public String toString() {
        return super.toString();
    }
}

Would be rewritten as:

record Point(double x, double y);

There are some other very interesting Java features which I would leave to your curiosity to find out.

Release Cycle

Recently, it was announced that Java would be using a 6-month release cycle, so we would expect a release every 6 months. The good news is that you can expect to get new features faster.

Java on Android

Google announced Kotlin as an official language and since then it has seen huge growths.

I do like Kotlin, I use Kotlin, but I am of the opinion that Kotlin isn't here to replace Java.

Now, you might have heard some Android devs complain of Java. I usually like them to be specific.

What they actually complain of is the verbosity of Java 7 whereas the latest to be released at the time of this writing is Java 12.

Kotlin looks cool on Android partly because Android developers can't access the latest Java features and are stuck using Java 7 ~ Java 8.

Nevertheless, most Android applications are still currently written in Java. Probably a lot of professional developers are fine using Java 7 :)

We all shouldn't make the mistake of comparing Kotlin to Java the way Swift was compared to Objective C.

Unfortunately, a lot of Android developers aren't aware of how far Java has come as a language because they still use the Java of their CS class.

By the way, I am an Android developer and I also think Kotlin is cool ;)

Java Is Still free

Oracle recently announced that they would be charging for the commercial use of Oracle JDK and long-term support. Well, it got to the headlines and people wrote a lot of factually incorrect articles.

To whom it may concern, Java is still free.

Most big companies who use Oracle JDK for their development wouldn't be so bothered by the change.

For people who are worried, there is no need to be!

As at JDK 11, OpenJDK has feature parity with Oracle's JDK. Hence, they are interchangeable.

Moreover, Amazon recently announced Amazon Corretto which is a no-cost, multiplatform, production-ready distribution of the Open Java Development Kit (OpenJDK).

Corretto comes with long-term support that will include performance enhancements and security fixes.

You could also go for other OpenJDK providers such as AdoptOpenJDK, there is actually no cause for alarm.

Java is still free.

Java's current rank as a language

Currently, Java is #1 language for the TIOBE index programming language ranking. It was also #2 in the GitHub's State of the Octoverse.

This isn's a sales pitch

This article isn't a quit your job and go learn Java article. Instead, I am here to tell you how far Java has come and where it is heading as a language.

Java's ability to keep on adapting has helped it remain one of the top languages for a very long period.

Discussion

pic
Editor guide
Collapse
lemuelogbunude profile image
Lemuel Ogbunude Author

What Oracle is saying is that OpenJDK would be supported for at least 6 months period after a release. Enterprises are more conservative and would want longer support so would get paid support from Oracle for longer periods.

Like I said OracleJDK and OpenJDK are functionally interchangeable.

But let's say you hate Oracle and do not want to use their JDK, no problem, you have other providers of production-ready OpenJDK,

For example, Amazon Corretto comes with long-term support that will include performance enhancements and security fixes. Amazon runs Corretto internally on thousands of production services.

You have other providers like AdoptOpenJDK.

Also, I agree with you that Java was is big on Android but if we look back, Java(1995) was around way before Android came (2008), Java was a top language way before Android came.

Java is used in many other areas apart from Android.

Java is currently used heavily in Big data, Artificial intelligence, IOT, backend development and critical systems.

I still say Oracle has work to do though, and they are working, like you said, MS and Apple are doing quite well.

I have looked at Swift and it's a lovely language.

Collapse
lysofdev profile image
Esteban Hernández

Spring is keeping Java alive despite great competition from Go and Rust in the server-side. Android, of course, keeps the JVM alive with Kotlin. I personally like Java's verbose style and I'd say a lot of the hate comes from people who aren't too familiar with Java's idioms. My only real criticism is the amount of memory that the JVM requires to run medium to large applications but this has been improving bit by bit.

Collapse
lemuelogbunude profile image
Lemuel Ogbunude Author

Yeah, Java is big on Spring.

And yes, a lot of hate for Java comes from people who aren't too familiar with the 'Java looks'. For example, someone coming from a C++ background might not have as many issues with Java as someone coming from a strictly Javascript background.

But as programmers, it's always good to explore other languages than the ones we are comfortable with, it helps us see things in different ways.

Collapse
andevr profile image
drew

As someone e who is just now learning Java, (8/11) I really love Java syntax and "verbose style" as well, in my opinion it makes it more readable. I had a really difficult time learning Javascript and understanding what was happening. Not so with Java.

Collapse
michael_vt_native profile image
Michael

Nicely said! I, too, think Java is seeing a revival thanks in large part to Spring and later Kotlin. JDK 11+ is getting even more exciting (as exciting as Enterprise App Dev gets).

And this is coming from a dynamic language traditionalist who grew up on PHP and ASP ;)

Collapse
saint4eva profile image
saint4eva

ASP is not dynamic.

Collapse
michael_vt_native profile image
Michael

Ah, but I'm talking the original ASP - Classic ASP - before the modern .NET version.

Collapse
arminreichert profile image
Armin Reichert

IntStream.rangeClosed(1, 10)
.filter(i -> i % 2 == 0)
.forEach(System.out::println);

Collapse
lemuelogbunude profile image
Lemuel Ogbunude Author

Yes, thank you Armin. I should have mentioned I used a static import of IntStream, that's why I didn't use "IntStream'.

Collapse
arminreichert profile image
Armin Reichert

It's not about the static import (which is fine), it's the unnecessary creation of an intermediate collection.

Thread Thread
lemuelogbunude profile image
Lemuel Ogbunude Author

Oh lol, my initial desire was to answer the "Lecturer's question" and create a list first, so the code was initially different.

It initially created a list, assigned it to a variable and then worked on it, but when I shortened the code I didn't bother on (I might have felt lazy :/) to remove the creation of an intermediate collection.

Thanks for the advice though.

elmuerte profile image
Michiel Hendriks

That says that Oracle isn’t going to support older Java versions, only working on the current and next versions. Which means other companies have to pick up backporting of fixes where needed. Something which has been going on for years already. (As the linked article also mentions wrt to Java 6 and 7)

Collapse
halileohalilei profile image
Halil Ibrahim Kayim

Thanks for this write-up. I am one of those people that hates Java after using more modern languages, but I was on the lookout for Java’s new features. I had really liked the changes in 8 and 9, but it still felt like it wasn’t there yet and I didn’t bother checking out the later updates. I may give it another go with all these new features.

Collapse
lemuelogbunude profile image
Lemuel Ogbunude Author

Yeah, Java was lacking a lot of features that modern languages gave.

Java is improving and we are seeing a lot of changes.

It wouldn't hurt giving it another try.

Collapse
elmuerte profile image
Michiel Hendriks

What do you mean Oracle is not supporting OpenJDK ? They are still actively contributing to it, and it is the reference Java implementation. GraalVM also depends on OpenJDK.
And besides Oracle there are other big companies who also back OpenJDK.

Collapse
pradeepravi profile image
Pradeep

Lemuel, Great stuff!

At times when there is a new Language coming every day, Java realigned itself, learnt what its problems are and worked on them, so as to continue to be relevant!

Love Java and love the fact I chose a language that survived 10+ years that I have been doing development

Collapse
zerh profile image
Eliezer Herrera

This lines like this...

 ArrayList<Integer> myList = new ArrayList<Integer>(); 

...are not totally true in "old java", the declaration of the generic object should use the generic args, but... not the instantiation. Should be like this:

ArrayList<Integer> myList = new ArrayList<>();
Collapse
drgrib profile image
Chris Redford

Even the version in 2019 Java looks pretty convoluted to me. Now it's looking like Scala, which I'm also not a fan of.

Check out the version of this code in Go:

package main

import "fmt"

func main() {
    a := []int{}
    for i := 1; i <= 10; i++ {
        a = append(a, i)
    }

    for _, num := range a {
        if num%2 == 0 {
            fmt.Println(num)
        }
    }
}

That's a full, executable program that I just wrote off the cuff in 30 seconds while looking at your blog code. I think it has both Java versions beat for striking the right balance of concision and clarity.

Collapse
lschultebraucks profile image
Lasse Schultebraucks

Super interesting post Lemuel! Thanks!

Collapse
lemuelogbunude profile image
Collapse
akiks profile image
Aki

When did Java introduce "records"?
Will that be a new feature in Java 13?

Collapse
lemuelogbunude profile image
Lemuel Ogbunude Author

Hi Aki, it's not yet a feature in Java. It might be implemented soon, but not sure when. There are talks about it, however:
cr.openjdk.java.net/~briangoetz/am...
dzone.com/articles/april-2019-upda...

Collapse
sharqawidev profile image
Abdulrahman Elsharqawi

But how can I learn this new java and master it like the old one? What is the best resources to do that?

Collapse
lemuelogbunude profile image
Lemuel Ogbunude Author

You can get conference talks that give nice updates such as this one: youtube.com/watch?v=J6fegDQPgps&t=1s

That is the Devoxx channel and it's great.

There is a great book manning.com/books/modern-java-in-a... which is aimed at helping you keep up with modern Java features.

Also, I share updates on my channel: youtube.com/channel/UCvoPG-_BHO2Ar...

Collapse
sesliu profile image
Ulisses

Java is still a modern programming language, many companies have projects created in Java, nowadays it can be used to develop API rest with Springboot, for example.