Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does the Java Runtime Environment compare with the .NET framework in terms of compilation process?

I am learning about the conversion of source code to machine code via the .NET and JRE Frameworks. To start off I did some research comparing the two processes and created this diagram. I need some help in criticizing its correctness, and more importantly adding any serious things I missed out to better understand the compilation pathway.

enter image description here

like image 653
jII Avatar asked Jun 28 '12 21:06

jII


People also ask

What is the difference between .NET and Java?

The most prominent difference between . Net and Java is that Java works on any operating system and . Net mainly focuses on different versions of Windows.

What is the difference between Java and Java Runtime Environment?

JDK(Java Development Kit) is used to develop Java applications. JDK also contains numerous development tools like compilers, debuggers, etc. JRE(Java Runtime Environment) is the implementation of JVM(Java Virtual Machine) and it is specially designed to execute Java programs.

Is .NET faster than Java?

Although Java has several speed features, it is still slower than.NET, which employs natively built languages such as C# and C++. However, they are both quicker and use less storage than Java.

Is .NET and Java similar?

Java is a platform-agnostic object-oriented programming language that supports multiple third-party operating systems. . NET is an open-source framework that supports only Windows operating system even being declared as a cross-platform toolset.


1 Answers

Both .NET and Java compile down to bytecode, that is an intermediate language which contains instructions for a virtual machine. It's not machine code because it cannot run directly on a physical machine. What happens instead (today at least; Java has a darker history in this regard) is that at runtime a just-in-time compiler is run which translates the VM instructions into native code that is then run directly. This has a major performance benefit over only interpreting it.

They differ in this regard a little. Oracle's Java implementation (Hotspot) uses a clever mix of interpretation, measuring and JIT compiling just the parts that are heavily used and interpreting otherwise. This is to reduce initial impact by the JIT compiler (which needs to run upfront otherwise, lengthening process startup time) while still allowing good performance where needed. .NET on the other hand always JIT-compiles all code that is used (unused code is not compiled, though).

Edit (2019): By now .NET also has tiered compilation where depending on what code runs a lot, that code will be optimized further.

As for a question you mentioned in your comments: Yes, the CLR and the JVM are the platforms such programs are run on. A virtual machine is a machine too, just less hardware-y. They both are tightly integrated with a corresponding framework, the Base Class Library for .NET and the Java class library for Java. Those are frameworks.

like image 135
Joey Avatar answered Oct 21 '22 07:10

Joey