Assertfail

Java vs C#

15 Jun 2019

Java started out as a very object oriented language. One of the nice things with Java (as a language) has been that the syntax has been quite stable for a long time. C# competes with Java for mainstream developer mindshare. C# has pushed better tooling and more features but was primarily focused on Windows.

For the last few years we have seen .net becoming a truer cross platform language with the .net core project and Microsofts acquisition of Xamarin. Due to the push towards micro services and Docker this makes a lot of sense since we will probably see more large scale enterprise software use some sort of micro service architecture to allow scaling of development teams.

Features

Implemented in both

Language Features

Some of the features we know and love in C# is nowadays also part of modern Java:

In the C# corner we are waiting on C# 8 for:

We see that Java uses standard generic class Optional<> with methods while c# uses ?. and ?? operators and uses Nullable<> for value types.

Tooling

Using Visual Studio Code to develop Java feels very productive. Using Jetbrains Intellij is nicer. I’m not a fan of Eclipse. For c# I usually prefer Visual Studio while Visual Studio Code works and you get some more sweet refactorings in Rider (or through Resharper).

Both Maven and NuGet are mature and enable decomposition into libraries.

Missing features added through extension

The missing part that becomes quite obvious as you start working on any project in Java is the lack of auto properties. However, there is Project Lombok that removes a lot of boilerplate from your code.

You would expect that in c# you’d use t4 template to reduce boilerplate.

Missing features

There isn’t any generic support in the Java runtime. This leads to some weirdness around type erasure.

Style

Differences

The style of stream and the usage of words are more in line with many other languages (see for instance Javascript, Ruby, Python). Notice the use of map, filter and reduce while in c# LINQ is more in line with SQL. This gives the code a slightly different flavor.

Checked exceptions cause some boilerplate code that becomes a bit more manageable with Result style error handling.

Similarities

There is validation in Java similar to the familiar attribute based validation in .net.

There are popular MVC frameworks for both. Spring should feel familiar to anyone using asp.net MVC.

There are some gotchas, but any .net developer or Java developer should be able to work in both. There might be a short term productivity loss.

Conclusion

Both languages have mature editor support. Many of the bread and butter programming tasks have feature support in both languages. There are some stylistic differences between the languages.

Tags


Comments or errors? Fork this post and do a pull request on github