
If you’re a recruiter in the tech space, you’ve no doubt heard about Java. Here’s a little bit about the programming language, including why it’s so popular, and the latest developments in its evolution. Having celebrated its 23rd anniversary in May, Java is a curious beast. Way 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, Java 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. The language is also constantly updated: Java SE 10 was released in March 2018, effectively making its predecessor (Java SE 9) obsolete.
Detailed Aspects
If you’re more familiar with the language—you’re a hiring manager who once coded, for instance—here are some things to know about the latest version of the language. First, it 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 callbacks, 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
In programming, 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.