Exploring the Latest Version of the Java Programming Language

Now approaching its 23rd anniversary in May, Java is a curious beast. Back when the programming language started, the web was in its infancy; and as websites burgeoned in popularity, so did Java’s usage: developers really liked a class-based, object-oriented language that seemed especially effective for client-server web applications (and, later, native apps for the Android mobile operating system). By the turn of the century, it was arguably the most popular language in the world, and has remained at (or near) the top of popular rankings such as the TIOBE index and RedMonk.

For those new to Java, it’s an auspicious time to learn the language: Java SE 10 was released in March 2018, effectively making its predecessor (Java SE 9) obsolete. This latest version of the language includes some very long-awaited features such as the addition of keyword var for declaring variables without explicitly declaring the type—a mere 11 years after C# did the same.

Keyword var reduces the verbosity of Java with a lot less boilerplate code. For instance:

List list = new LinkedList<>();

 

Becomes:

var list = new LinkedList<>();

 

You can’t just declare a variable with var xyz; the declaration has to have an initial value so the compiler can determine the type. This means your code looks neater, like this:

var  letters = List.of("a", "b", "c");
for (var ch : letters)
    System.out.print(ch + ", ");

 

It’s not quite as powerful as in C#; for instance, you’ll have to wait until a future version for var working with Lambda expression parameters. That being said, it is still a significant improvement that increases the readability of programs. I’ve seen variable declarations where the type name alone is 60 characters or longer; given the impact of var in C#, it’ll probably prove even more effective in Java in reducing this kind of ungainliness.

Other new features in Java 10 include improvements to the Garbage Collector, refined thread call-backs, an experimental JIT compiler, and more. You can read all about them in the release notes. Let’s look closer at unmodifiable collections, which may confound some people new to Java.

Extra Unmodifiable Collections

You should be careful to distinguish between unmodifiable and immutable: Immutable collections can’t be changed at all, and have been included since Java 9. An unmodifiable collection is one that does not support any modifications at all, so there are no methods such as add, remove or clear.
In addition, an unmodified collection is usually a read-only wrapper of an existing collection. You can’t modify the collection through that reference, but another reference may allow it. (However, the immutable collection can’t ever change.)

Here’s an example:

Collection myList = new ArrayList();
myList.add("Hi!");
Collection unModList = Collections.unmodifiableList(myList);
Set immutableSet = Set.of("alpha", "beta", "gamma”, "omega");

 

Here, myList is mutable, as the myList.add(“Hi!”); shows. The unmodList uses the unmodifiableList method. You can still modify myList directly, but not through unModList. The immutableSet is shown for comparison; it cannot be altered.

New Release Cycle

Java 10 is the open-source reference implementation of the Java SE 10 platform. It’s the first of Oracle’s new six-month release cycles. A new Java Development Kit (JDK) will be released every six months, and a long-term support version (LTS) every three years, as with Ubuntu, Fedora and Red Hat Linux releases.

This Java 10 release was originally planned for September 2018, but at some point was switched to March 20, 2018. (It’s a new world when software gets delivered early!) You can get a feel for what’s coming in future releases on the OpenJDK site. The next release, JDK 11, currently lists four JDK Enhancement Proposals (JEPS), with all proposals listed here.

A great measure of a programming language’s popularity is the number of jobs available in its ecosystem; by that standard, Java is doing pretty well, with over 35,000 jobs advertised on Dice.com in the U.S. and 3,400 in the UK. (That said, C# and JavaScript also have roughly the same number of jobs in both countries.)

What of the Enterprise?

Previously known as J2EE, Java EE has been largely abandoned by Oracle, which moved it to an open-source foundation (the Eclipse Foundation) in mid-2017. Personally, I find this baffling because enterprise is where the big bucks are; if you want to get into enterprise development, you should familiarize yourself with Java EE.

Conclusion

Java seems to have gone in two directions. One is in mobile development; for example, you can use it to program Android applications (in addition to Kotlin). Within the enterprise, Java EE is used extensively, although a variety of other languages (including Python, C#, and even VB.NET) are battling it for dominance in the desktop-development space.

Nearly four years ago, the ACM published an article that showed Python with the edge over Java as the language used to teach introductory-programming courses. But the latter is still the number-one programming language in large businesses, meaning it can prove lucrative to developers who are fully in the swing of their career. Consider that a big incentive to learn it!

Related Posts

Post a Comment

Your email address will not be published.