When C# is the right choice, and when it is not

The other pages of this group compare one task at a time; this one answers the question the group exists for. The short answer is that neither language wins, and that the honest reason to choose one is rarely the language: it is the platform the program has to run on, the team that has to maintain it, and the library that already solves the problem. The rest of the page is the long answer, and it names the cases where each language is the wrong choice.

What each is good at

AreaC#Java
Type systemrecords, record structs, structs, nullable reference types, pattern matching with list patternsrecords, sealed interfaces, record patterns, no value classes yet
Genericsreified: the type argument exists at run time, and a list of int stores intserased: one class per generic type, and a primitive needs a wrapper
Asynchronyasync and await in the language, Task in the libraryCompletableFuture in the library, virtual threads since Java 21
QueriesLINQ with two syntaxes and deferred executionthe Stream API with collectors
DesktopWinForms, WPF, MAUI for Windows; Unity for gamesJavaFX, Swing; Android is the large one
ServerASP.NET Core, one of the fastest web stacks in the benchmarksSpring, Quarkus, the largest enterprise ecosystem
RuntimeCoreCLR with generational GC, tiered JIT and NativeAOTHotSpot with several collectors, C1 and C2, GraalVM native image
PortabilityWindows, Linux and macOS; the SDK is one downloadevery platform with a JVM, which is more of them than .NET has

When Java is better

When C# is better

Tools, deployment and onboarding

The build page measured the two toolchains in this container: a C# framework-dependent publish of a small program is 128 KiB and starts with dotnet Program.dll; a jar of the same program is 4 556 bytes and starts with java -jar. The first Maven build of a new project took 20.2 seconds because Maven downloaded its plugins; a C# build of a console project took about three seconds from a cold start and less after it, because the SDK is installed with the compiler.

Onboarding is the other side of the same coin. A newcomer to C# installs the SDK, runs dotnet new console and has a program that builds; a newcomer to Java installs a JDK, learns that javac and java are two commands, and meets Maven or Gradle on the first day of a real project. Both languages read alike to a programmer who knows either, which the pages of this group show by putting the two listings next to each other: the syntax is a week, and the platform is a month.

Maintainability

The fair conclusion: choose the platform first, the team second and the language third. When the platform is Windows or Unity, that is C#. When it is Android, a JVM-only host or an enterprise stack already written in Java, that is Java. When the platform allows both, the difference this group measured is small enough that the team's experience and the library it needs should decide, and a language argument that rests on a benchmark of a loop should end with the benchmark page.

Exercises

  1. Take a program you maintain and list the platform constraints that decide its language.
  2. Find one library your project needs that exists in only one of the two ecosystems.
  3. Compare the onboarding of both in your team: what a new member installs and what they read on the first day.
  4. Write the case against your own preference, using a page of this group as evidence.

Questions

A new set of questions in a new order every time. Choose one answer for each, then check.

  1. What should decide the language first, according to the page?

    Answer

    The platform the program must run on

    The page puts the platform first, the team second and the language third.

  2. Which platform is Java's large advantage?

    Answer

    Android

    Android is Java and Kotlin, and no C# runtime is first class there.

  3. Which area does the page name as C#'s advantage?

    Answer

    Value types and Span for a performance-sensitive program

    Structs, Span and ref struct are the C# answer to allocation.

  4. What did the throughput page measure?

    Answer

    122.6 ms against 129.8 ms medians, inside the noise

    The page refuses to make a choice on that difference.

  5. What does dotnet give a team that a Java project assembles?

    Answer

    The compiler, package manager, test runner and publisher in one tool

    The page names the single toolchain as the C# advantage.

  6. Which language warns about a null dereference at compile time?

    Answer

    C#, with nullable reference types

    The null page shows the warning and the Java message at run time.

  7. What is the cost of Java's checked exceptions?

    Answer

    Verbose signatures and callers that must decide

    The page calls the trade verbosity against visibility.

  8. What did the build page measure for a small C# publish?

    Answer

    128 KiB

    The publish folder of the records program is 128 KiB.

  9. When is C# the wrong choice?

    Answer

    When the target platform has no .NET and the team and libraries are Java

    The page lists the platform, the team and the libraries as the reasons.

  10. What does the page say about a language argument based on a benchmark?

    Answer

    It should end with the benchmark page, because the difference is inside the noise

    The measured difference was five percent of a loop.

The C# program was built with the .NET SDK 10.0.303 and the Java program with OpenJDK 21.0.13.1 (javac 21.0.13.1), both run on Alpine Linux 3.24.3 (x86_64, four processors) in a Docker container.

Article author: Arthur Isaev