I’m not going to rehash any of the billions of web pages out there about Java. I just want to summarize some of my thoughts on it.
I am about to start a new job that will be much more focused on Java. My previous work as a software developer has been almost exclusively focused on front-end web development in JavaScript. JavaScript is my first language, my best language, and I really enjoy working in it.
I am perfectly willing to work in Java if somebody pays me too, and I am even Oracle certified in Java, but I have some criticisms of the language.
Java is rigidly “object oriented” to the point of extreme tedium. JavaScript functions are first class objects, which means you can pass a function into another function as an argument and just generally a function is a data type of the language. It can be stored as the value of a variable. Java has no such thing. In Java, all functions are methods of an object (except maybe lambda expressions, which I’ll exclude for the moment). In Java, when the thing you really want to do is just encapsulate a subroutine (a function) and pass it around somehow for re-usability, because of the rigid OOP nature of Java, you are required to make it the method of an object. This results in silly objects whose entire purpose is just to execute a method. Sometimes these objects only exist for long enough to execute the method and then they vanish. I call this the ActionDoer anti-pattern because I don’t know if anybody else has named the programming pattern before.
It’s not possible in Java even to define inner functions for the sake of dividing a complex method into small subroutines. Each of those small subroutines must itself be a method on an object. This causes people to write a lot of small private methods to serve that purpose, which is an anti-pattern in my opinion. A subroutine or a helper function is not the same thing as a private method.
More recently Java has been trying to make it easier to write something sort of like anonymous first class functions. It’s still super tedious in Java. I stand by that. But since I’m not really an expert on recent developments in java, I don’t want to talk further on that topic, or on lambda expressions.
Java is not really and truly object oriented. Java contains classes. A “class” in Java is not just an abstract language construct. A class is a thing, like an object but not an object. A class can store data. A class is a singleton. Basically a class is a singleton instance of a very special kind of object. The thing that makes a Java class into a singleton object and not just a language construct is that classes can store data inside static fields. A static, non-constant field on a class is basically a global.
Java is way too verbose. You constantly have to repeat data types, over and over.
If you are brand new to programming and you are trying to develop basic skills to make yourself marketable in the workplace, you might just be asking: “should I learn Java?” A broad, open-ended question that pretends to have a simple yes or no answer.
Ultimately, for now, I think the answer is simply “yes”. Java doesn’t have to be your first language. It doesn’t have to be your best language. But yes, for now, every software engineer of any style should know some Java. Anyone aiming to be a web developer for sure should learn Java because it is so heavily used for backend web development, especially using the Spring framework. Also Java is very similar to C#, which is also quite popular. Knowing Java will help you understand C# if your career takes you in that direction. So, yes, learn some Java.