Java vs .NET: how the two platforms compare
Java and .NET solve the same problem in remarkably similar ways: you compile to an intermediate bytecode, a virtual machine with a just-in-time compiler and a garbage collector runs it, and a large standard library does the rest. The differences lie in history, languages, governance and ecosystem rather than in fundamental capability.
Architecture
| Java | .NET | |
|---|---|---|
| Intermediate code | Java bytecode (.class, packaged in JARs) | Common Intermediate Language (in assemblies, .dll) |
| Runtime | Java Virtual Machine (HotSpot, OpenJ9 and others) | Common Language Runtime (CoreCLR) |
| Ahead-of-time option | GraalVM Native Image | Native AOT |
| Main languages | Java, Kotlin, Scala, Groovy | C#, F#, Visual Basic |
| Package registry | Maven Central | NuGet |
| Build tools | Maven, Gradle | dotnet CLI / MSBuild |
Open source and platforms
The historical contrast, "Java runs everywhere, .NET runs on Windows", no longer holds. Modern .NET (from .NET Core in 2016 to today's .NET releases) is open source under the .NET Foundation and runs on Windows, Linux and macOS. Java's reference implementation is OpenJDK, also open source, with builds from many vendors. The older .NET Framework (4.x), which hosts ASP.NET Web Forms, remains Windows-only.
Languages
C# and Java started close and diverged. C# added properties, events, LINQ, async/await, value types defined by users (struct), records and pattern matching relatively early; Java has added lambdas, records, pattern matching and virtual threads over its recent releases. Generics differ technically: Java erases type arguments at run time, whereas .NET keeps them (reified generics), so List<int> stores real integers without boxing.
Web development
- Java: Spring (Spring Boot, Spring MVC), Jakarta EE, Quarkus, Micronaut.
- .NET: ASP.NET Core (MVC, Razor Pages, Blazor, minimal APIs); on .NET Framework, Web Forms and MVC 5 (see the ASP.NET programming models).
What decides in practice
- The skills already in the team and the existing code base.
- Integration needs: Microsoft-centric environments (Active Directory, SQL Server, Azure, Office) lean towards .NET; large JVM ecosystems (big-data tooling, Android with Kotlin) towards Java.
- Tooling preferences: Visual Studio and Rider for .NET; IntelliJ IDEA, Eclipse and VS Code for Java.
Performance differences between the two depend far more on the application than on the platform; both are used for high-throughput services.
See also OOP concepts in C#.
Concepts that map one to one
| Java | .NET / C# |
|---|---|
| JAR | Assembly (.dll) |
| package | namespace |
| interface, abstract class | interface, abstract class |
| JDBC | ADO.NET |
| JPA / Hibernate | Entity Framework |
| Servlet / Spring MVC controller | HTTP handler / ASP.NET MVC controller |
| JUnit | xUnit, NUnit, MSTest |
Official documentation
- Microsoft Learn: What is .NET?, Common Language Runtime overview
- OpenJDK: openjdk.org · Oracle: Java Language and VM Specifications