Sometimes we choose technologies because of affinity. I think python, linux and vim are good examples for me. Other times the choice is less authentic, more circumstantial.

Because of various interviews I have had exposure to some languages that I haven’t thought about in a long time or at all, just to prepare for some interviews.

Intellij idea

My experience with Java has been very limited. It was one of the languages that I studied as part of a university course on programming languages. A few years after that, I decided to give it a go to create an interface for sailing rating calculation using swing (I believe, I can’t find the code anymore). Beyond its superficial similarities to C++ and the single inheritance restriction, I don’t know much about it.

So for a few days I decided to study and get a intellij setup locally with some containerisation. The setup with nixos was trivial for shell.nix:

let
config = {
    allowUnfree = true;
};
pkgs = import <nixpkgs> {inherit config;};
in pkgs.mkShell {
    # nativeBuildInputs is usually what you want -- tools you need to run
    nativeBuildInputs = with pkgs.buildPackages; [jetbrains.idea];
      shellHook = ''
      '';
}

and some local firejail configuration

$cat ~/.config/firejail/idea.local
include /etc/firejail/idea.local
blacklist ${HOME}/.ssh
...

Java the language

The language itself is actually quite pleasant. I can’t tell if it is because of all the DDD stuff I read or simply because of alignment, but it looks like a healthy set of choices that don’t go too complicated and favour object orientation. My main reference points are python and C++ so I will compare with them often.

Encoding is the first obvious sticky point. Java uses utf-16 as a default instead of utf-8. In general utf-16 seems like a stickier choice for programming languages as they are written mostly in ascii.

Classes and Interfaces are a healthier alternative to multiple inheritance, which is IMO very difficult to manage in C++ and sort of OK but not quite in python. I still prefer rust model than java’s but it is an improvement overall.

I did not know that nested classes are a thing in java. Like in python it is a bit about namespacing, but there are some weird considerations about scoping. It is worth noting that static-ness of a class affects the nested classes.

In the same way it is possible to define an Anonymous class, which looks a lot like a javascript definition of an anonymous function. I find it a bit of a trap but I can see some uses for quick customisation.

Generics are a bit similar syntactically to C++ templates. They are not as powerful as C++ but they are more integrated with the type system like python annotations. I can see it getting complicated but I thought that it is a more cohesive implementation than C++’s. These disappear after compilation.

The annotations have the same syntax than python decorators, and there are a few built in. I find it particularly confusing with python but I don’t think they are a bad thing.

There is the concept of an abstract class which is similar to an interface but allows variables and non static methods. I can’t tell if this is a good idea or not as it adds a choice.

The two types of types There is this list of primitive types (C-like) and abstract types (class like) documentation

These are similar to C++ standard types vs the abstract implementation in the standard library (say a vector vs a char array).

I think these are necessary like in C++ because the language allows to work with low level abstractions for performance reasons. Python has an edge in clarity with the cost of not having true access to the C types (say a 4 bytes int)

Other aspects:

  • syncronisation primitives are similar to both python and C++ (for threads in particular).
  • Iterators and other syntax feel like an add-on to the language instead of a first class citizen like in python
  • Exceptions are like in python and part of the type system, which is a bonus

Final thoughts

I honestly liked it more than what I thought. 20 years ago a big sticky point was the JVM and IDEs. But nowadays it seems like a solved problem in the sense that the performance is very good and it is stable. There are build systems to deal with dependencies and multiple compilation units.

The language feels like it grew to specialise on the heavy object oriented-pattern world instead of the systems world like rust or C++. What I would call corporate world. It isn’t as ergonomic or descriptive as python but it isn’t as bad as C++ where domain matters. When compared to python its type system is much better and it seems to scale in a way that python can’t.

I can see an alternative self getting into java around 2009 instead of the python+C combo. Most likely I would be working for bigger corporations, closer to software architecture and further away from linux and operating systems.

In exchange I would have missed the python revolutions of data, webapps and general glue that python offers.

For today it seems like a perfectly reasonable choice. I believe that if I had to work with a new language I would prefer rust or golang, but not by a lot.