1.4 Intermediate language


How does Java achieve platform independence? Java source codes are compiled into byte codes (which are stored in .class files) by the Java compiler. Byte codes are portable because when they are executed, they are interpreted on-the-fly by the JVM for that specific platform. The JVM “ for say the Macintosh operating system “ understands both byte codes and how to translate them into native Macintosh machine codes that the Mac operating system understands. Similarly, the JVM for the Windows operating system knows how to translate byte codes into native machine codes for the Windows operating system.

The idea is suspiciously similar for .NET (see Figure 1.1). .NET source codes (whether written in J#, C# or any other .NET language) are compiled by a language-specific compiler into MSIL (or Common Intermediate Language-CIL) “ these are both commonly abbreviated to IL. IL is .NET's equivalent to Java byte codes. IL codes are then distributed as .NET assembly files to the client where they are executed.

Figure 1.1. Language-specific source codes are precompiled into IL codes which are language-neutral, then distributed in assembly files. On the client machine, IL codes are then JIT-compiled into native machine codes when executed within the CLR.

graphics/01fig01.gif

On the client which has the .NET runtime installed, the IL code executes within CLR. The CLR [12] works very much like JVM or JRE. It provides a virtual environment in which the IL codes 'bathe'.

[12] The CLR is also commonly known as the '.NET runtime'. These two terms are synonymous.



From Java to C#. A Developers Guide
From Java to C#: A Developers Guide
ISBN: 0321136225
EAN: 2147483647
Year: 2003
Pages: 221
Authors: Heng Ngee Mok

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net