A question about .NET

Started by
3 comments, last by Michalson 18 years, 2 months ago
Hello, What is the difference between .NET and the JVM? Isn't it just another interprator? If so then isnt it better to write on non .net langs? Thanks, Spirit.
This world is ruled by big furry CATS!! :)Meow! :)
Advertisement
Neither .NET nor Java are interpreted (anymore). Both are just-in-time compiled to native code. A significant advantage of .NET is that it was designed to be language-agnostic, so compilers for many different languages have been written for it (C#, VB.NET, PERL.NET, FORTRAN.NET, F#, COBOL.NET, IronPython, C++/CLI, etc). Java bytecode ops can be generated by any language, too (Jython, Processing), but options are relatively few and far between, and those that exist are sometimes limited (Processing, for example).

Currently, Java bytecode is more portable (Solaris, Linux, OS X, Windows), so if that's a primary consideration then go with Java.
I know basic Java, and now i also know basic C# (wich is about the same)

It wasnt a question of me trying to choose a lang, I just wanted to know, btw you said that the java code isnt interprated anymore? how so? i mean it does not make an executable file and stuff... no?
This world is ruled by big furry CATS!! :)Meow! :)
JVM was designed specifically for the Java language. While it is certainly possible to build a compiler for almost any language that creates Java language binaries, it would pose some challenges and the resulting code might not be as effecient (the JVM bytecode isn't a generic set of CPU like instructions - it contains many language specific opcodes for dealing with Java objects and arrays among other things). By comparison .NET was designed to be language neutral - it provides a mechanism so that most any language can communicate effecient code.

The other major difference is that the JVM was originally designed with bytecode emulation in mind (as stated, most JVM implimentations now compile to native code using Just In Time compiling), while the .NET standard was designed specifically for just in time compiling. This creates a problem as the Java opcodes are optimized for the best emulated execution speed, rather then to preserve high level constructs to provide the best just in time compiling, both for actual binary execution, and for the creation of those binaries (aka the slower then a 486 startup time of even a simple notepad in Java).
Quote:Original post by Ancient Spirit
I know basic Java, and now i also know basic C# (wich is about the same)

It wasnt a question of me trying to choose a lang, I just wanted to know, btw you said that the java code isnt interprated anymore? how so? i mean it does not make an executable file and stuff... no?


Both Java and .NET use a process called Just in Time compiling to generate binary (platform specific) code.

Think of compiling as a two step process.

In the first step, the compiler takes apart your semi-english language code (i = 1;) and turns it into something it can understand. So instead of a bunch of ASCII characters, it now has a set of information it can understand that says you want to set a variable to a specific value.

In the second step, the compiler, now understanding exactly what you want to do, expresses that in machine specific instructions. Often the compiler will optimize for the instruction set it is using, for example doing some math using MMX opcodes (optimization can also come in step 1 by removing redundent instructions).

Both the Java and .NET compilers can be thought of as a half way compiler, one that completes step 1, but leaves step 2 for the Just in Time compiler to do. However the Java compiler, because it was originally designed with interpretation in mind, does a little bit of step 2 as well. The result of this is that not only does the Java JIT have to backtrack a little (decompile some of the Java bytecodes), there is also a "lossy" effect - some of the high level information can be lost in the step 1 process, reducing the effectiveness of the step 2 optimizer.

If you have access through a university (or want to pay), here is a in depth comparison Stacking them up: a Comparison of Virtual Machines. The paper creates a compiler designed to generate both Java bytecode and .NET IL code (Intermediate Language) from the same source file. The main finding is that while .NET is the more optimal solution, some platforms benefit more from Java's legacy ability to be interpretted - specifically very memory limited devices like cellphones that would not be able to JIT compiler Java or .NET in a reasonable amount of time due to the need for complex swapping operations.

Edit: Link to the article if you have an ACM login.

This topic is closed to new replies.

Advertisement